Last active
February 8, 2022 13:42
-
-
Save sidferreira/72e17d29b224ca93cf86901ed1ceb032 to your computer and use it in GitHub Desktop.
React Navigation + MobX Integration (React Native Based)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// App/index.js | |
import React, { Component } from 'react' | |
import { View, StyleSheet } from 'react-native' | |
import { initStore, Provider } from '../Store' | |
import RootContainer from '../Containers/RootContainer' | |
import RootNavigator from './RootNavigator' | |
const store = initStore({RootNavigator}) | |
export default () => ( | |
<View style={styles.container}> | |
<Provider store={store} > | |
<RootContainer /> | |
</Provider> | |
</View> | |
) | |
const styles = StyleSheet.create({ | |
container: { | |
flex: 1 | |
} | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Store/index.js | |
import { useStrict } from 'mobx' | |
import NavStore from './navStore' | |
export { Provider } from 'mobx-react' | |
useStrict(true) | |
export class RootStore { | |
nav:NavStore | |
constructor ({RootNavigator}) { | |
this.nav = new NavStore(RootNavigator) | |
} | |
} | |
export const initStore = (options) => new RootStore(options) |
@MrShakes did this like 2 or 3 years ago and I'm back to redux. I think navigation service is a better approach too
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This doesn't work for react-navigation greater than 2.2.0, any updates?