Reducer
Reducer的核心概念
代码示例
function counterReducer(state, action) {
switch (action.type) {
case 'increment':
return { count: state.count + 1 };
case 'decrement':
return { count: state.count - 1 };
default:
return state;
}
}
// 使用示例
const initialState = { count: 0 };
const incrementAction = { type: 'increment' };
const newState = counterReducer(initialState, incrementAction); // { count: 1 }Reducer的应用场景
Last updated