react-native and redux

一、安装相关库

yarn add redux
yarn add react-redux
yarn add react-navigation

二、创建相关文件夹

react-native and redux_第1张图片
相关文件夹

三、创建Root.js文件

import React, { Component } from 'react';
import { Provider } from 'react-redux';
import configureStore from './store/ConfigureStore';

import App from './container/App';

const store = configureStore();

export default class Root extends Component {
  render() {
    return (
      
        
      
    )
  }
}

四、创建/src/constainer/App.js

'use strict';

import { combineReducers } from 'redux';
import test from './test';

const rootReducer = combineReducers({
    test: test,
});

export default rootReducer;

五、创建/src/store/ConfigureStore

'use strict';

import React, { Component } from 'react';
import { createStore, applyMiddleware } from 'redux';
import thunkMiddleware from 'redux-thunk';
import rootReducer from '../reducers/index';

const createStoreWithMiddleware = applyMiddleware(thunkMiddleware)(createStore);

export default function ConfigureStore(initialState) {
    const store = createStoreWithMiddleware(rootReducer, initialState);
    return store;
};

你可能感兴趣的:(react-native and redux)