redux 学习

55 阅读1分钟

特性

  1. 单一数据源

image.png

  1. State是只读的

image.png

  1. 使用纯函数来执行修改 为了描述,action如何改变state tree ,需要编写reducers Reducers 只是一些纯函数

image.png

组成

action-事件

本质是一个对象

image.png

Reducer

本质是一个函数,用于 响应 发过来的actions,经过处理,把state 发送给Store
接收两个参数,一个初始化state, 一个action 

image.png

Store

image.png

总结

image.png

    store 通过createStore(reducer)创建store
    
    reducer 是一个纯函数接收一个初始state,和action
    
    function(state=initState,action)
    
    
    action 是一个 包含type和对state修改的Object
    
    项目中 通过store.dispatch(action) 来更新store
          通过store.subscribe(()=>{})来监听store变更

React-redux

image.png

image.png

Provider

image.png

image.png

connect

image.png

image.png

中间件

image.png

juejin.cn/post/710496…