Skip to content

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 but each page fetches its own slice of data.

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 useRef guard ensures actions fire exactly once per mount, including under Strict Mode’s double-invoke.
  • action/save is 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])], ]}>

ParameterType
__namedParameters{ actions: Action[]; children?: ReactNode; }
__namedParameters.actionsAction[]
__namedParameters.children?ReactNode

Element