Created
May 17, 2019 16:59
-
-
Save dewey92/8424f9382b26ece1c104bd89b47348d1 to your computer and use it in GitHub Desktop.
Counter Reducer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// useCounterReducer.js | |
import * as React from 'react'; | |
const counterReducer = (state, action) => { | |
if (action.type === 'INCREMENT') { | |
return state + 1; | |
} | |
if (action.type === 'DECREMENT') { | |
return state - 1; | |
} | |
return state; | |
} | |
// Hooks | |
export const useCounterReducer = () => { | |
return React.useReducer(counterReducer, 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment