2

Quote from site:

We fully support Redux, MobX and other state management libraries.

But if I try to pass store and Provider to registerComponent() I still receive error, that react-mobx can't inject store that doesn't exists. Also I've tried Provider by megahertz, but it seems like this code is outdated.

Are there any ways to use react native navigation v2 with mobx?

Stalder
  • 21
  • 1

1 Answers1

1

If you create a HOC in where you provide the store with a provider it works.

const addStore = (Component, ...props) => {
  return class App extends React.Component {
    render() {
     return (
      <Provider venues={Stores}>
        <Component {...{
          ...this.props,
          ...props,
        }} />
      </Provider>
    );
   }
  }
};

export async function RegisterScreens() {
  Navigation.registerComponent('venuesOverview', () => addStore(VenuesOverview));
}
Sven Jens
  • 25
  • 5
  • Do you have any suggestions how to use this solution in a case when first there's a single root, for example a login screen, and then afterwards a bottom tab layout is set using setRoot? In this case the goal would be to have the store available both for the login and and the tabs. – holparb Nov 23 '18 at 07:17