--- id: third-party-mobx title: MobX sidebar_label: MobX --- ## MobX MobX is one of the most popular state management libraries used by applications sized from small to large. With the introduction of the new React Context API, MobX can now be very easily integrated in React Native Navigation projects. In the example we will be creating a small Counter app. :::info Note With the introduction of the new Context API, there is no need to use `Provider` pattern with MobX and you can now just use the React Context API. Also the example uses `mobx-react-lite` but you can use the normal `mobx-react`. ::: ## Create a Counter store. Let's first create a counter store using MobX. ```tsx // counter.store.js import React from 'react' import { observable, action } from 'mobx' class CounterStore { @observable count = 0 @action.bound increment() { this.count += 1 } @action.bound decrement() { this.count -= 1 } } // Instantiate the counter store. const counterStore = new CounterStore() // Create a React Context with the counter store instance. export const CounterStoreContext = React.createContext(counterStore) ``` ## Consuming the store You can consume the Counter store in any React components using `React.useContext`. ```tsx // Counter.js import React from 'react' import { Button, Text, View } from 'react-native' import { observer } from 'mobx-react-lite' import { CounterStoreContext } from './counter.store' const CounterScreen = observer(() => { const { count, increment, decrement } = React.useContext(CounterStoreContext) return ( {`Clicked ${count} times!`}