Next.js Discord

Discord Forum

state asigned twice

Answered
Sun bear posted this in #help-forum
Open in Discord
Sun bearOP
Answered by fuma
You are saying that you don’t want to run the generateRandomSeen on the server right?
Just set the state in a useEffect, then it will only generated at the client side, run once only.
View full answer

10 Replies

Sun bearOP
i dont know how hydration works
how can i asign only once
when you open website it is different and then it changes again
You are saying that you don’t want to run the generateRandomSeen on the server right?
Just set the state in a useEffect, then it will only generated at the client side, run once only.
Answer
This can fix hydration errors
Nice to hear that! Mark it as the solution if it works :meow_party:
Original message was deleted
See there