π›ˆπž‚π—Ώπžˆπ’†π’ˆπ–π°π›ˆ 𝐜0πŸƒ3𝗿
π›ˆπž‚π—Ώπžˆπ’†π’ˆπ–π°π›ˆ 𝐜0πŸƒ3𝗿
TtRPC
Created by π›ˆπž‚π—Ώπžˆπ’†π’ˆπ–π°π›ˆ 𝐜0πŸƒ3𝗿 on 5/24/2023 in #❓-help
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]);
11 replies