如何将redux存储包装到我的App.js中

时间:2018-01-19 05:22:30

标签: react-native redux

import React from 'react';
import { View, Text } from 'react-native';
import { StackNavigator } from 'react-navigation';
import HomeScreen from './Home.js';
import EntryPoint  from './src/containers/EntryPoint.js';
import Stage2 from './src/containers/Stage2.js';


const RootNavigator = StackNavigator({
    Home: {
        screen: HomeScreen,
        navigationOptions: {
            headerTitle: 'Material Management',
        },
    },
     EntryPoint: {
         screen: EntryPoint,
         navigationOptions: {
             headerTitle: 'Entry Point'
         }
     },
    Stage2 : {
        screen : Stage2,
        navigationOptions : {
            headerTitle : 'Stage 2'
        }
    }
});

export default RootNavigator;

以上代码是我的App.js 我想在它周围包装redux商店。我怎么做 。无法使用React-native找到适当的redux设置文档。

1 个答案:

答案 0 :(得分:2)

import { createStore,bindActionCreators } from 'redux'
import { connect, Provider  } from 'react-redux'
function mapStateToProps(state) {
   return state;
}

function mapDispatchToProps(dispatch) {
    return bindActionCreators(Actions, dispatch);
}
let Container = connect(mapStateToProps,mapDispatchToProps)(RootNavigator);

export default class APP extends Component{
    render(){
        return (<Provider store={store}>
                     <Container/>
            </Provider>)
    }
};