一、安装相关库
yarn add redux
yarn add react-redux
yarn add react-navigation
二、创建相关文件夹
三、创建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 (
<Provider store={store}>
<App/>
</Provider>
)
}
}
四、创建/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;
};