Zustand persist rehydration completes after first render
0 reputation · 03 Feb 2021, 11:27 UTC
Persisted Zustand state not available on initial mount
This question concerns Zustand's persist middleware and whether rehydrated state is available before the first component render. The goal is to diagnose whether recovered data from localStorage is guaranteed to exist when a selector-based component mounts, or whether the component always renders with the initial state until rehydration completes.
Persist rehydrates asynchronously, and onRehydrateStorage exposes start and finished events. Zustand does not document a synchronous readiness guarantee for restored state across supported releases. It is unclear whether reading persisted values during initial render is safe or whether rendering must wait for the finished callback.
Does onRehydrateStorage finished fire before any mounted component reads the store? Can a selector safely return persisted state during the first render? Is there a synchronous rehydration guarantee in current Zustand versions?