Server Side Rendering

When using server side rendering, the components are rendered only once. Since components are never unmounted, observer components would in this case leak memory when being rendered server side.

To avoid leaking memory, call useStaticRendering(true) when using server side rendering which essentially disables observer.

  1. import { useStaticRendering } from 'mobx-react'
  2. // use whatever condition you want/need, this is just an example
  3. if (process.env.SSR) {
  4. useStaticRendering(true)
  5. }

Note: Despite the naming, the function IS NOT A REACT HOOK. The name was decided long before the React Hooks were introduced. You should call it only once at the root of your server side code.