hydrate
hydrate(domain: Domain, { values: Map<Store<any>, any> | {[sid: string]: any} }): void
A companion method for serialize. Hydrates provided values into corresponding stores within a provided domain. The main purpose is an application state hydration on the client side after SSR.
Arguments
domain
: a Domain objectvalues
: a mapping from store sids to store values or a Map where keys are Store objects and values contains initial store value
Example
Populate store with a predefined value
import {createStore, createDomain, fork, serialize, hydrate} from 'effector'
const domain = createDomain()
const store = domain.createStore(0)
hydrate(domain, {
values: {
[store.sid]: 42,
},
})
console.log(store.getState()) // 42