redux使用
redux是react状态管理的库。它创建了一个全局的状态树,react组件共享这个状态树。分为三个部分,store,action,reducer。
store
1.store中存放着需要用到的状态,且只能由一个store
2.store由createStore(reducer)创建
3. store只能通过action触发reducer来改变状态
action
action是一个普通对象,通过type来触发指定行为
它可以存放任何数据。
reducer
通过store.dispatch(action) 来执行特定行为,返回一个新的状态树