Skip to content

Instantly share code, notes, and snippets.

@AlexFrazer
Created January 24, 2024 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexFrazer/6c65469d943cfb267efaba780046dc1c to your computer and use it in GitHub Desktop.
Save AlexFrazer/6c65469d943cfb267efaba780046dc1c to your computer and use it in GitHub Desktop.
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