mst-utils
v0.3.1
Published
Collection of utilities to help you use mst for server side rendering and more.
Downloads
40
Readme
Mobx State Tree Utils
Collection of utilities to help you use mst for server side rendering and more.
Features
- Server and client hydration
- dispatch mobx-state-tree actions
Installation
yarn add mst-utils
or
npm install mst-utils
Getting Started
import { store } from 'mst-utils';
import counter from './stores/counter';
export default store.setup({ counter });
Initialize stores
Somewhere on the server initialize your models by calling store.create(state)
.
Dehydrate
Dehydrate your state on the server
import { dehydrate } from 'mst-utils';
const state = hydrate();
// Do something with state
window.__STATE = state
Rehydrate
Rehydrates your state from the server. Should be called in your index client file.
import { rehydrate } from 'mst-utils';
rehydrate();
Dispatch
Dispatch any function from your mst models in the store.
import { dispatch } from 'mst-utils';
dispatch('counter.increment');