Replies: 7 comments 6 replies
-
@dai-shi is this really impossible to achieve with nextjs. Please help me sensei. |
Beta Was this translation helpful? Give feedback.
-
Not sure how Redux solves this, but I'd be interested to know. |
Beta Was this translation helpful? Give feedback.
-
@lordvcs the simple way u can add suppressHydrationWarning on your html tag attribute. ` const countStore= useStore(state => state.count) const [count, setCount] = useState(0) return count in jsx` |
Beta Was this translation helpful? Give feedback.
-
Look like we must use
|
Beta Was this translation helpful? Give feedback.
-
This error only happen in development don't worry too much, you can disable the persist middleware for |
Beta Was this translation helpful? Give feedback.
-
@lordvcs I'm having the same issue. Did you manage to solve this without using useEffect? |
Beta Was this translation helpful? Give feedback.
-
Struggling with this error as well. I am trying to set Then hydrate when needed after components mounted. etc.. https://docs.pmnd.rs/zustand/integrations/persisting-store-data#skiphydration EDIT: Yep! That totally fixed it for me.
'use client';
import { useEffect } from 'react';
import { useCart } from '@store/CartProvider';
const ClientRehydrator = () => {
const cartStore = useCart();
useEffect(() => {
cartStore.persist.rehydrate(); // Manually rehydrate the store
}, [cartStore]);
return null; // Render nothing
};
export default ClientRehydrator; |
Beta Was this translation helpful? Give feedback.
-
I have been trying to use zustand with nextjs for weeks now. Everything works as intended except when I use persist, in which case I get the error "Warning: Text content did not match. Server: ..." in the console
Here is the codesandbox I have created https://codesandbox.io/s/mystifying-https-upvdxy[increment count, refresh page within the codesandbox browser and open the codesandbox console to see the error]
I know that I can solve the issue by doing an extra step of setting the state in useEffect as shown in this stackoverflow answer https://stackoverflow.com/a/66374800/2532763 but however I was able to get similar functionality with redux without having to use an useEffect. So I am guessing its possible to do the same with zustand too.
P.S I tried it with context too https://github.com/pmndrs/zustand#react-context, however I get the same error.
Does anyone know how to solve this? Any help is appreciated
Beta Was this translation helpful? Give feedback.
All reactions