How to Persist Your MobX State

Photo by Kaitlyn Baker on Unsplash

How to set up mobx-persist

I will assume you already have your MobX app configured and running. If not, make sure to check out the following article about how to get started with MobX and React.

  • UserStore
  • SettingsStore
  • store - The store you want to persist
  • initialState - An optional initial state
  • customArgs - Custom arguments for serializr (See documentation)

How to use mobx-persist

After we finished the configuration, we can start persisting our stores!
In our AuthStore we want to save the authToken to keep the user logged in. So we create the store and add the observable:

Indie App Developer 👨‍💻 Never miss a new article about programming or starting your own business with my newsletter news.joech.io!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store