Course lesson
Use TypeScript to Type React useReducer
We get the state of our board from a reduce function. It currently has no error but also has no type safety since everything is inferred to be of type any. useReducer is generic and accepts type arguments, describing the state as well as the events it can...
- Duration
- 5 min
- Access
- Included
- Transcript
- Retained from source evidence
We get the state of our board from a reduce function. It currently has no error but also has no type safety since everything is inferred to be of type any. useReducer is generic and accepts type arguments, describing the state as well as the events it can expect to receive.
The simplest way to add types to a useReducer is to add them directly to the reducer function itself. We will do this by using an alias for our types.