how can i integrate redux store to react native?

2019-09-02 06:19发布

问题:

I have created basic ui with react native and Navigation React Navigation V2 My App's entry file(App.js) like this

//App.js

const App = createSwitchNavigator(
  {
    StartupScreen: Validator, //validating accesstoken existing or not if existing navigate to Dashboard otherwise login page 
    Login:Login, 
    DashBoard: Dashboard //tabbed view
  },  
  {
    initialRouteName: 'StartupScreen',
  }
);

export default App

how can integrate here with redux?

that is how can I pass store to app like

<Provider store={store}> <App /></Provider>

to get store every page.

Thanks in advance

回答1:

So you need to return the Provider wrapping your navigator.

// App.js

const App = createSwitchNavigator(
  {
    StartupScreen: Validator,
    Login:Login, 
    DashBoard: Dashboard
  },  
  {
    initialRouteName: 'StartupScreen',
  }
);

export default function() {
  return <Provider store={store}><App /></Provider>;
}

Do not forget to import the Provider and to create the store using reducers and etc.



回答2:

I have implemented Redux in My template. You can refer this https://github.com/vishaljadav24/react-native-base-template