Inconsistency between UI and data when using Zustand and NextJs #1943
Unanswered
andrey-sheremeta
asked this question in
Q&A
Replies: 1 comment 9 replies
-
|
I just went through all this but I'm using the App router rather than the Pages router, so I'm using server and client components. I got it to work doing this though I had to also wrap the client component provider component in another server component that does the initial fetch. That might not make any sense if you're not used to using the App router. You may find this helpful, as they seem to be doing what you're after using getServerSideProps and all that. It's worth noting once I got the initial state with props and context providing and all that my store and UI are working flawlessly. |
Beta Was this translation helpful? Give feedback.
9 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello.
I faced one problem while using NextJs(12) and Zustand(4). There is an inconsistency between UI and data, leading to many different defects.
F.e.
but it leads to different defects (addition rerendering, inconsistency between UI and data and etc.). Is there any alternative way to update the store, without using useEffect?
you have two pages A & B; each page returns its data via
getServerSideProps. so on the client side when a user navigates from page A to page B, to properly render a page we need to update Zustand store with new data received from the server. The current approach that is described here https://docs.pmnd.rs/zustand/guides/initialize-state-with-props encourages to useuseEffectIn my understanding, it's quite a critical thing.
repo with example - https://github.com/andrey-sheremeta/zustand-state-update
I was trying to remove
useEffectit seems work but then only react returns an error - facebook/react#18178 (comment)Beta Was this translation helpful? Give feedback.
All reactions