Next.js Discord

Discord Forum

How to get data from server into zustand store instantly

Unanswered
Keyhole wasp posted this in #help-forum
Open in Discord
Keyhole waspOP
I am fetching the user in the server and returning it to layout as a header "X-USER". The data is there on first render. Now, how do I immediately put it in zustand store? All the guides I can find say to use useEffect and setUser there, but obviously this results in a horrid first render with user as null as it renders before useEffect runs. What am I supposed to do? Not use zustand and instead prop drill user data into the entire app? That would at least work on first render.

2 Replies