Skip to content

Instantly share code, notes, and snippets.

@sathinduga
Last active September 10, 2018 15:13
Reducer
import { COUNTER_ADD, COUNTER_SUBTRACT } from "../actions/action_types";
const initialState = {
count: 0
};
const counterReducer = (state = initialState, action) => {
switch (action.type) {
case COUNTER_ADD:
return {
...state,
count: state.count + 1
};
case COUNTER_SUBTRACT:
return {
...state,
count: state.count - 1
};
default:
return state;
}
};
export default counterReducer;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment