NextJS, next-auth, zustand persist middleware
Unanswered
Cape horse mackerel posted this in #help-forum
Cape horse mackerelOP
Hello everyone.
I'm using technologies mentioned in the post title however I'm facing an issue when I want to set user data to the localStorage to persist user data within localStorage.
I'm following https://docs.pmnd.rs/zustand/integrations/persisting-store-data#usage-in-next.js
and within layout component (not root layout) I'm doing
If I include
I'm using technologies mentioned in the post title however I'm facing an issue when I want to set user data to the localStorage to persist user data within localStorage.
I'm following https://docs.pmnd.rs/zustand/integrations/persisting-store-data#usage-in-next.js
and within layout component (not root layout) I'm doing
const authStore = useAsyncStore(useAuthStore, (state) => state);
const { data } = useSession();
useEffect(() => {
if (data?.user) authStore?.setUser(data.user);
}, [authStore]);If I include
data.user as dependency within useEffect array the app goes crazy, re-rendering all the time. Any idea or maybe some other approach how should I tackle this one?1 Reply
Short-tailed Albatross
hey
hoe did you handle clearing the state/ updating states on new pages,
in my case i am using zustand when the entityPage Pnloads and that might be tricky if there are many entities to be opened,
so was wondering how to clear upon change
any advice will be amazing, thank you
hoe did you handle clearing the state/ updating states on new pages,
in my case i am using zustand when the entityPage Pnloads and that might be tricky if there are many entities to be opened,
so was wondering how to clear upon change
any advice will be amazing, thank you