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
You don’t want to run a mutation on component render
Yeah. Probably useEffect will help. But overall this problem shouldn’t exist that you are signedIn, but not in a DB
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
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
@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 ?
Correct me if I’m wrong, but could you run the mutation in a
getServerSideProps
function? Theoretically that way it should only run onceI’d need to see the code to say anything about that
This is a terrible idea
Clerk webhook or as a blocking step in like an
api.trpc.getUserProfile.useQuery()
callGood point, I forgot about the useQuery hook, thanks for the correction