小编vbr*_*eak的帖子

Redux中的动作应始终唯一吗?

在此示例中,我使用名为ADD_TODO的操作

import { createStore, combineReducers } from 'redux';

function todos(state, action) {
    state = state || [];
    switch (action.type) {
        case 'ADD_TODO':
            return state.concat([ action.text ]);
        default:
            return state;
    }
}

function counter(state, action){
    state = state || 0;
    switch (action.type){
        case 'INCREMENT':
            return state+1;
        case 'DECREMENT':
            return state-1;
        case 'ADD_TODO':
            return state+100;
        default:
            return state;
    }
}

var app = combineReducers({
    todos: todos,
    counter: counter
});

var store = createStore(app);
store.dispatch({ type: 'ADD_TODO': text: 'buy eggs' }); …
Run Code Online (Sandbox Code Playgroud)

redux

6
推荐指数
1
解决办法
938
查看次数

标签 统计

redux ×1