如何在 React Native 中将 redux 商店包装到我的 App.js 中 [英] How to wrap redux store to my App.js in react native

查看:38
本文介绍了如何在 React Native 中将 redux 商店包装到我的 App.js 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 设置的正确文档.

The above code is my App.js I want to wrap the redux store around it. How do i do that . Couldn't find a proper documentation for redux setup with React-native.

推荐答案

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

这篇关于如何在 React Native 中将 redux 商店包装到我的 App.js 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆