Persist and hydrate MobX-state-tree stores.
npm i -S mst-persist
const SomeStore = typesconst someStore = SomeStore
persist(key, store, options)
- key string The key of your storage engine that you want to persist to.
- store MST store The store to be persisted.
- options object Additional configuration options.
- storage localForage / AsyncStorage / localStorage
Any Storage Engine that has a Promise-style API similar to
localForage. The default is
localStorage, which has a built-in adaptor to make it support Promises. For React Native, one may configure
redux-persist's Storage Engines should also be compatible with
- jsonify bool Enables serialization as JSON (default:
- whitelist Array<string> Only these keys will be persisted (defaults to all keys).
- blacklist Array<string> These keys will not be persisted (defaults to all keys).
- storage localForage / AsyncStorage / localStorage Any Storage Engine that has a Promise-style API similar to
returns a void Promise
Node and Server-Side Rendering (SSR) Usage
Node environments are supported so long as you configure a Storage Engine that supports Node, such as
This allows you to hydrate your store server-side.
For SSR though, you may not want to hydrate your store server-side, so in that case you can call
if typeof window !== 'undefined' // window is undefined in Node
With this conditional check, your store will only be hydrated client-side.