tRPCttRPC
Powered by
π›ˆπž‚π—Ώπžˆπ’†π’ˆπ–π°π›ˆ 𝐜0πŸƒ3𝗿�
tRPCβ€’3y agoβ€’
10 replies
π›ˆπž‚π—Ώπžˆπ’†π’ˆπ–π°π›ˆ 𝐜0πŸƒ3𝗿

useEffect and useMutation error about conditional rendering of hooks

I am using t3 stack with tRPC, and I am trying to mark all emails as seen when the page loads by using useEffect, but this seems to give me an error about conditional rendering of hooks.

Are there any other ways I can accomplish this?

  const { mutate: markAsSeen } = api.paMail.markAsSeen.useMutation({
    onError: () => {
      ToastComponent({ message: "Database error", type: "error" });
    },
  });

  useEffect(() => {
    markAsSeen({ sentTo: paPlayer!.id });
  }, [markAsSeen]);
  const { mutate: markAsSeen } = api.paMail.markAsSeen.useMutation({
    onError: () => {
      ToastComponent({ message: "Database error", type: "error" });
    },
  });

  useEffect(() => {
    markAsSeen({ sentTo: paPlayer!.id });
  }, [markAsSeen]);
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

useMutation in useEffect dependency array causes infinite loop
.nickman..nickman / ❓-help
3y ago
wrapper on useMutation (and another for useQuery) for creating multiple hooks
MarMMar / ❓-help
3y ago
useMutation error is array not message
Answer OverflowAAnswer Overflow / ❓-help
3y ago
useMutation called twice
Answer OverflowAAnswer Overflow / ❓-help
2y ago