Skip to content

Instantly share code, notes, and snippets.

@sahoosunilkumar
Created May 13, 2019 13:55
Show Gist options
  • Save sahoosunilkumar/17e9754cce75d53f8eb41b0a1d26d0af to your computer and use it in GitHub Desktop.
Save sahoosunilkumar/17e9754cce75d53f8eb41b0a1d26d0af to your computer and use it in GitHub Desktop.
import { INCREMENT, DECREMENT } from "../actions/types";
const initialState = {
counter: 0
};
const counterReducer = (state = initialState, action) => {
switch (action.type) {
case INCREMENT:
return {
...state,
counter: Number(state.counter) + Number(action.payload)
};
case DECREMENT:
return {
...state,
counter: Number(state.counter) - Number(action.payload)
};
default:
return state;
}
};
export default counterReducer;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment