Mobx: Should I use observable in SSR?

Created on 13 Oct 2016  路  1Comment  路  Source: mobxjs/mobx

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:

  • maintaining the stores singleton among multiple requests
  • the observer components would watch for changes on the stores singleton

Most helpful comment

I have seen that the best approach is to initialise a new instance of the stores at every requests.

>All comments

I have seen that the best approach is to initialise a new instance of the stores at every requests.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rodryquintero picture rodryquintero  路  3Comments

hellectronic picture hellectronic  路  3Comments

bakedog417 picture bakedog417  路  3Comments

weitalu picture weitalu  路  3Comments

kirhim picture kirhim  路  3Comments