O'Reilly logo

React Native - Building Mobile Apps with JavaScript by Vladimir Novick

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

MobX

Now, after we've seen how Redux can be hooked up to our app, let's take a look at how we can do this with MobX. First of all, as Redux has three reducers, we will have three stores in MobX: NavigationStore, UserStore, and FeedStore.

Let's set up the Navigation store. It will look like this:

import { AppNavigator } from '../AppNavigator'; import { observable, action } from 'mobx'; import { NavigationActions } from 'react-navigation';  class NavigationStore {     @observable.ref navigationState = AppNavigator         .router         .getStateForAction(NavigationActions.init({}))      @action dispatch = (action, stackNavState = true) => {         const previousNavState = stackNavState ? this.navigationState          : null;         return this.navigationState = AppNavigator             .router

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required