Demo of using MobX store in a Next.js app
Demo of using MobX stores in a Next.js app.
yarn
yarn dev
In the browser, try navigating to posts (/post/1
etc.) and clicking "Update".
The example started from this blog post by Mike Lewis which is an adaptation of the official with-mobx
example. I have added these features:
useMobxStores()
hook which is a slight wrapper around React contextAs noted e.g. here, more complex stores cannot be automatically serialized via the built-in JSON.stringify
– there can be circular references etc.
So the example implements the "initial data" pattern:
App.getInitialProps
, stores return their plain data representation.render
function, stores are created again from these initial data.