Skip to content

Instantly share code, notes, and snippets.

@naush
Last active August 14, 2020 02:12
Show Gist options
  • Save naush/98515a4c80b673cc94ba6a34952adb09 to your computer and use it in GitHub Desktop.
Save naush/98515a4c80b673cc94ba6a34952adb09 to your computer and use it in GitHub Desktop.
type DarumaContextType = {
state: WishState,
dispatch: React.Dispatch<any>,
};
const DarumaContext = React.createContext({} as DarumaContextType);
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] = useReducer(reducer, WishState.PENDING);
return (
<DarumaContext.Provider value={{ state, dispatch }}>
<Daruma />
<Buttons />
</DarumaContext.Provider>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment