Zustand on server side
Answered
rex1410 posted this in #help-forum
rex1410OP
Guys, when using zustand, I read this thread where people said that using zustand states on server side is a problematic approach with hidden bugs. But can I instantiate the zustand state on server side? Fetch from DB -> Set first Zustand State -> send to client side. Will this work without any issues?
Answered by rex1410
found an even better guide down in the docs, for the exact scenario https://docs.pmnd.rs/zustand/guides/nextjs
8 Replies
you could fetch the data on server and pass the data as props then provide it to zustand store with context api
https://docs.pmnd.rs/zustand/guides/initialize-state-with-props
https://docs.pmnd.rs/zustand/guides/initialize-state-with-props
rex1410OP
@Ray thanks for the link, I missed this.
rex1410OP
found an even better guide down in the docs, for the exact scenario https://docs.pmnd.rs/zustand/guides/nextjs
Answer
rex1410OP
@Ray @joulev any idea about this one? its like a follow up doubt for this.. https://nextjs-forum.com/post/1225330229539504168
Prairie yellowjacket
hey did you manage to find a good solution?
rex1410OP
yes
the link I shared above is the thing
In short, you create a React Context, and provide state using that