Redux

reducer(state, action) → store.dispatch(action) → final state

store 管理状态的盒子 → getState() dispatch(action)分发

→ reducer 用来修改state的方法,返回state

→ action 改变的状态,{type: 'xxx',text: ‘xxx’}

import redux from 'redux';

const reducer = function (state, action) {
    switch (action.type) {
        case 'add_Todo':
            return state.concat(action.text);
        default:
            return state;
    }
};

const addTodo = function (text) {//actionAreator
    return {
        type: 'add_Todo',
        text: text
    };
};

const store = redux.createStore(reducer, []);

store.dispatch(addTodo('xxx'));
store.getState();

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。