switch statement react
import * as actionTypes from "../store/actions/actionTypes";
const initialState = {
counter: 0,
name: "Ginny",
tasks: ["cut onion", "drive car"],
};
const reducer = (state = initialState, action) => {
switch (action.type) {
case actionTypes.INCREMENT:
return {
...state,
counter: state.counter + 1,
};
case actionTypes.DECREMENT:
return {
...state,
counter: state.counter - 1,
};
case actionTypes.ADD:
return {
...state,
counter: state.counter + action.value,
};
case actionTypes.ADD_TEN:
return {
...state,
counter: state.counter + action.payload,
};
default:
return state;
}
};
export default reducer;