HydrateStore
HydrateStore(
__namedParameters):Element
Defined in: store/HydrateStore.tsx:32
Merges a batch of server-fetched actions into the existing store on first
render. Used by SSR routes that fetch data after the store was created at
a parent level — e.g. Next App Router pages whose layout owns the
Why dispatch during render (not in useEffect):
- During SSR this runs on the server too, so server-rendered HTML already reflects the hydrated state. The client then re-runs with the same actions and lands on the same state — no “flash of empty state.”
- A
useRefguard ensures actions fire exactly once per mount, including under Strict Mode’s double-invoke. action/saveis idempotent: re-dispatching the same payload yields the same state. So even in pathological re-render scenarios there’s no correctness risk, only a redundant pass.
Place it inside a route’s server component, wrapping the client tree:
<HydrateStore actions={[
[‘action/batch’, banks.map(b => [‘action/save’, [‘bankAccounts’, b.id], b])],
]}>
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
__namedParameters | { actions: Action[]; children?: ReactNode; } |
__namedParameters.actions | Action[] |
__namedParameters.children? | ReactNode |
Returns
Section titled “Returns”Element