Question · JavaScript and React course · Module 12: React and TypeScript
Explicit Typing of useState
When is it necessary to explicitly specify the generic type in useState?
Answer options
- When the initial value is null, an empty array, or a union type
- Only in class components
- When the initial value is an object with many fields
- Always - TypeScript never infers types in hooks
You can check the correct answer by solving this task in the CodeWorlds game.