20. 使用Redux创建Store的4步骤 - yiqunkeke/react-jianshu-shangguigu-zty GitHub Wiki
- 首先安装 redux
npm install redux -S
- 在src目录下,新建 store 文件夹,并且新建 index.js 作为 store入口:
// 创建store
import { createStore } from 'redux'
const store = createStore()
export default store
- 创建reducer,在src/store目录下,创建 reducer.js
const defaultState = {}
export default (state = defaultState, action) => {
// state 里面存放的是整个Store当中存储的数据
return state
}
- 把创建好的reducer(笔记本)传递给Store
import { createStore } from 'redux'
import reducer from './reducer' // 引入reducer(笔记本)
const store = createStore(reducer) // 把reducer(笔记本)作为第一个参数,传递给store
export default store