Appearance
react 中使用redux
本节目标:理解“react 中使用redux”的核心思路,并能把它用于实际开发或面试表达。 使用
Redux流程
- 定义当前项目有什么功能(常量):
actionTypes.js
const INCREMENT = 'increment';
const DECREMENT = 'decrement';定义当前项目的默认状态,放到reducer中:reducer.jslet initialState = {
};创建容器let store = createStore(reducer)可以在外面进行派发动作,默认渲染一次。