Skip to content

Commit

Permalink
Add stringify advice to MobX example readme. (#2541)
Browse files Browse the repository at this point in the history
  • Loading branch information
4nduril authored and timneutkens committed Jul 12, 2017
1 parent 530b561 commit 24c2e99
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/with-mobx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

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.
Expand Down

0 comments on commit 24c2e99

Please sign in to comment.