Stalder
Stalder

Reputation: 21

How to use MobX with react-native-navigation by Wix?

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?

Upvotes: 2

Views: 825

Answers (1)

Sven Jens
Sven Jens

Reputation: 25

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));
}

Upvotes: 1

Related Questions