zustand empty on inital render
Hello,
I am currently using nextjs, trpc and zustand. I'm running into a problem where my zustand state is undefined on reacts inital render of the page.
- I use trpc's prefetch function is a layout.tsx file to fetch data on the server, the data here is used on all routes within my
Here is my workspace selector component, it is at the top of my dashboard sidebar and shares state between different pages on the dashboard, which is why i plan on using zustand. I am only using zustand for the current selected workspace at this time, as I know trpc has a built in state management cache for data retrieved from the server.
/dashboard directory (this data is mainly for my dashboard sidebar
- the data is being hydrated with trpcs hydrateclient comonent
- i have a loading.tsx file to catch all trpc queries which are still running, if there are any a loading state will be displayed until all data is fetched.Here is my workspace selector component, it is at the top of my dashboard sidebar and shares state between different pages on the dashboard, which is why i plan on using zustand. I am only using zustand for the current selected workspace at this time, as I know trpc has a built in state management cache for data retrieved from the server.

1 Reply
The problem I am having is on the intial render, after the loading.tsx file has finished and the page content is visible, zustand store is still marked as
undefined for the initial render of the page, causing quick data changes on the page from undefined -> selected value
What can I do to stop this from happening? here is a visual of the issue: