redux全局状态管理

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 {…}

})
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值