how can i integrate redux store to react native?

醉酒当歌 提交于 2019-12-11 18:17:15

问题


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



来源:https://stackoverflow.com/questions/50601353/how-can-i-integrate-redux-store-to-react-native

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!