Skip to content

Confused about Next.js implementations #168

Discussion options

You must be logged in to vote

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:

import { observable } from '@legendapp/state';
import { enableReactUse } from '@legendapp/state/config/enableReactUse';
import { useMount } from '@legendapp/state/react';

enableReactUse();

c…

Replies: 2 comments 8 replies

Comment options

You must be logged in to vote
2 replies
@FleetAdmiralJakob
Comment options

@jmeistrich
Comment options

Comment options

You must be logged in to vote
6 replies
@jmeistrich
Comment options

Answer selected by FleetAdmiralJakob
@FleetAdmiralJakob
Comment options

@jmeistrich
Comment options

@FleetAdmiralJakob
Comment options

@jmeistrich
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants