Put in order · JavaScript and React course · Module 12: React and TypeScript
Order of Typing Component State
Arrange the steps for creating typed state in React in the correct order:
Items to put in order
- Use useState with a generic: useState<Planet | null>(null)
- Call the setter with data matching the interface
- Define an interface for the data (e.g. interface Planet { ... })
- Use state in JSX with safe access (?.)
You can check the correct answer by solving this task in the CodeWorlds game.