Last active
August 14, 2020 02:12
-
-
Save naush/98515a4c80b673cc94ba6a34952adb09 to your computer and use it in GitHub Desktop.
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
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