Skip to content

Instantly share code, notes, and snippets.

@dewey92
Created May 17, 2019 16:59
Show Gist options
  • Save dewey92/8424f9382b26ece1c104bd89b47348d1 to your computer and use it in GitHub Desktop.
Save dewey92/8424f9382b26ece1c104bd89b47348d1 to your computer and use it in GitHub Desktop.
Counter Reducer
// 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