Confused about Next.js implementations #168
-
Hey, can someone show me how can I define a global observable the Legend way in Next.js (I'm using a client component), which I can update onClick. AND that's for me the part that I think I especially don't understand: How the hell I can show an image based on this observable? Thank you for your answers, because I'm really frustrated now and really don't want to go back to Zustand. I always got hydration errors next.js crashed or it simply didn't work. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
Could you share some code, would be easier to review that way. |
Beta Was this translation helpful? Give feedback.
-
@jmeistrich |
Beta Was this translation helpful? Give feedback.
Oh, there can sometimes be a hydration error when using
persistObservable
because that is local-only state. It should run ok but just display a warning in development mode. To fix that you could remove the persistence, or make sure it's running client-only.What we do is make sure our components that use persisted state run client-side only. See:
https://nextjs.org/docs/messages/react-hydration-error#solution-1-using-useeffect-to-run-on-the-client-only
We have this
useCanRender
hook for this purpose: