Why is this re-rendering infinitely

This block of code is causing infinite re rendering causing the app to crash with this error in console: Unique constraint failed on the constraint: PRIMARY ❌ tRPC failed on user.createUser: Invalid prisma.user.create() invocation:
9 Replies
cje
cje2y ago
You don’t want to run a mutation on component render
goldenretriever
Yeah. Probably useEffect will help. But overall this problem shouldn’t exist that you are signedIn, but not in a DB
cje
cje2y ago
doing it on useEffect is still bad, even with an empty dependency array you don't want to mutate resources on page load ever dangerous pattern
goldenretriever
It would solve the issue quickly, but I’d just check if user’s in a DB and do the mutations on sign in itself
Sugan_Selvam
Sugan_SelvamOP2y ago
@goldenretriever / @cje I understand using useeffect is a bad idea, thats why I didnt add it in the code. Any inputs on how do I use mutation on sign in itself ?
del.hydraz
del.hydraz2y ago
Correct me if I’m wrong, but could you run the mutation in a getServerSideProps function? Theoretically that way it should only run once
goldenretriever
I’d need to see the code to say anything about that
theo (t3.gg)
theo (t3.gg)2y ago
This is a terrible idea Clerk webhook or as a blocking step in like an api.trpc.getUserProfile.useQuery() call
del.hydraz
del.hydraz2y ago
Good point, I forgot about the useQuery hook, thanks for the correction
Want results from more Discord servers?
Add your server