Skip to content

Commit 24c2e99

Browse files
4nduriltimneutkens
authored andcommitted
Add stringify advice to MobX example readme. (#2541)
1 parent 530b561 commit 24c2e99

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

examples/with-mobx/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ This example is a mobx port of the [with-redux](https://github.com/zeit/next.js/
3737
}
3838
```
3939

40+
### Rehydrating with server data
41+
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.
42+
4043
## The idea behind the example
4144

4245
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.

0 commit comments

Comments
 (0)