I am learning server side rendering techniques. This is how I inject my stores into the context on client side
render(
<Router
history={browserHistory}
onUpdate={() => {
stores.routerStore.setPathName(location.pathname)
}}
render={(props) => (
<Provider {...stores}>
<RouterContext {...props} />
</Provider>
)}
routes={routes}
/>,
document.getElementById('app')
)
On the server instead of injecting the mobx stores, I am injecting a plain object
renderToString(
<Provider {...data}>
<RouterContext {...renderProps} />
</Provider>
)
Is it right?
If I inject the mobx stores on the server I would have the unwanted effect of:
I have seen that the best approach is to initialise a new instance of the stores at every requests.
Most helpful comment
I have seen that the best approach is to initialise a new instance of the stores at every requests.