1.在src目录下新建一个store文件夹,并且在store文件夹中新建两个文件index.js和reducer.js
2.安装redux,在命令行中输入:
yarn add redux
3.index.js文件中的代码:
//引入redux
import { createStore } from 'redux';
import reducer from './reducer';
//创建store并且传递把reducer传递进来
const store = createStore(reducer);
export default store;
4.reducer.js中的代码
//state:所有数据信息
const defaultState = {
inputValue: '123',
list:[1,3]
}
//设置state的默认数据:defaultState
export default (state = defaultState, action) => {
return state;
}
4.在TodoList.js中先需要导入state文件夹下的index.js
import store from './store/index'
将获取到的inputValue中的数据传