serialize
A companion method for fork. Allows to get a serialized value for all the store states within a scope. The main purpose is an application state serialization on the server side during SSR.
Arguments
scopeScope: a scope object (forked instance)ignoreOptional array of Store to be omitted during serialization (added 20.14.0)onlyChangesOptional boolean flag to ignore stores which didn't changed in fork (prevent default values from being carried over network)
Returns
An object with store values using sids as a keys
Example#
Serialize forked instance state
Note on onlyChanges#
With onlyChanges, this method will serialize only stores which were changed by some trigger during work or defined in values field by fork or hydrate(scope). Once being changed, a store will stay marked as changed in given scope even if it was turned back to default state during work, otherwise client will not update that store on its side, which is unexpected and inconsistent.
This allows to hydrate client state several times, for example during route changes in next.js