Created
January 24, 2024 18:41
-
-
Save AlexFrazer/6c65469d943cfb267efaba780046dc1c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
interface State { | |
// whatever state you want here | |
} | |
type Action = { type: "CHANGE" } | { type: "RESET" }; | |
function reducer(state: State, action: Action) { | |
const initialState = { ...state }; | |
switch (action.type) { | |
case "CHANGE": | |
// do whatever you want to do on change | |
case "RESET": | |
return { ...initialState }; | |
default: | |
return state; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment