tezvyn:

Typing React Component Props with TypeScript

Source: react.devbeginner

Use TypeScript to define a 'contract' for your component's props with an `interface` or `type`. This catches bugs by ensuring data passed to a component has the correct shape. The footgun: files with JSX must use the `.tsx` extension.

Use TypeScript to add static type definitions to your React components, creating a 'contract' for what props they expect. By defining an `interface` or `type` for your props object, you catch bugs and enable editor autocomplete. The main footgun is forgetting that any file containing JSX must use a `.tsx` extension, or TypeScript won't process it correctly.

Read the original → react.dev

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

Typing React Component Props with TypeScript · Tezvyn