redux就是一个JavaScript容器
redux中的三大核心:store action reducer
Component组件通过store.dispatch()发送一个action
Store通过dispatch()派发action给reducer
state:数据 (服务端的数据,组件的状态,App级别的状态)
store :单一数据源(所有的state都在store中,把action和reducer联系到一起),只读的(要更改store就要触发action)
getState()获取state
dispatch() 发送acton
subscribe()注册监听
通过subscribe()的返回值注销监听
const store=createStore(传递reducer)
action: 唯一修改store的方式(视图,网络就不能修改state)
派发action: store.dispatch({type:TYPE,index:1}) 派发给reducer
reducers:就是一些纯函数,来执行修改(连接store和action,返回新的state给store) 必有要有返回值,store才能接受新的state
reducer=(state,action=>{
return {…}
})