Skip to content

Instantly share code, notes, and snippets.

@naush
Last active August 14, 2020 02:12
Show Gist options
  • Save naush/771e2f8e213ceed9f3d54dee8a12ee77 to your computer and use it in GitHub Desktop.
Save naush/771e2f8e213ceed9f3d54dee8a12ee77 to your computer and use it in GitHub Desktop.
enum Actions {
PAINT,
UNDO,
}
const reducer = (state: WishState, action: any) => {
switch (action.type) {
case Actions.PAINT:
return forward(state);
case Actions.UNDO:
return backward(state);
default:
throw new Error();
}
};
const App = () => {
const [state, dispatch] = React.useReducer(reducer, WishState.PENDING);
return (
<>
<Daruma
state={state}
/>
<Buttons
dispatch={dispatch}
/>
</>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment