Commit 24c2e995 authored by Tobias Barth's avatar Tobias Barth Committed by Tim Neutkens

Add stringify advice to MobX example readme. (#2541)

parent 530b5610
...@@ -37,6 +37,9 @@ This example is a mobx port of the [with-redux](https://github.com/zeit/next.js/ ...@@ -37,6 +37,9 @@ This example is a mobx port of the [with-redux](https://github.com/zeit/next.js/
} }
``` ```
### Rehydrating with server data
Be aware that data that was used on the server (and provided via `getInitialProps`) will be stringified in order to rehydrate the client with it. That means, if you create a store that is, say, an `ObservableMap` and give it as prop to a page, then the server will render appropriately. But stringifying it for the client will turn the `ObservableMap` to an ordinary JavaScript object (which does not have `Map`-style methods and is not an observable). So it is better to create the store as a normal object and turn it into a `Observable` in the `render()` method. This way both sides have an `Observable` to work with.
## The idea behind the example ## The idea behind the example
Usually splitting your app state into `pages` feels natural but sometimes you'll want to have global state for your app. This is an example on how you can use mobx that also works with our universal rendering approach. This is just a way you can do it but it's not the only one. Usually splitting your app state into `pages` feels natural but sometimes you'll want to have global state for your app. This is an example on how you can use mobx that also works with our universal rendering approach. This is just a way you can do it but it's not the only one.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment