Created
September 16, 2024 12:02
-
-
Save tjunghans/de591c8b4f6523ec2bccaf4d9506709c to your computer and use it in GitHub Desktop.
React Reducer
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
export enum ActionType { | |
CreateSomething, | |
UpdateSomething, | |
DeleteSomething, | |
RetrieveSomething | |
} |
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
import { Dispatch } from "react"; | |
type Something = { name: string; }; | |
export type State = { | |
somethings: Something[]; | |
}; | |
export type CreateSomething = { | |
type: ActionType.CreateSomething; | |
payload: { | |
name: string; | |
}; | |
}; | |
export type UpdateSomething = { | |
type: ActionType.UpdateSomething; | |
payload: { | |
id: string; | |
name: string; | |
}; | |
}; | |
export type DeleteSomething = { | |
type: ActionType.DeleteSomething; | |
payload: { | |
id: string; | |
}; | |
}; | |
export type RetrieveSomething = { | |
type: ActionType.RetrieveSomething; | |
payload: { | |
id: string; | |
}; | |
}; | |
type ReducerActions = CreateSomething | UpdateSomething | DeleteSomething | RetrieveSomething; | |
export type Dispatcher = Dispatch<ReducerActions>; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment