Setting Up React and TypeScript Flashcards

1
Q

What does React.ReactNode allow as children in a React component?

A

It allows JSX elements and strings.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you define a type for props in React with TypeScript?

A

Use type Props = { type?: string; heading: string; children: React.ReactNode; closable?: boolean; onClose?: () => void; }.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How can you ensure type safety when passing props in React components?

A

Define a Props type and use it when declaring the component function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How can you define a state type explicitly in React with TypeScript?

A

Use a generic argument, e.g., const [visible, setVisible] = useState<boolean>();.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the purpose of React DevTools’ Profiler panel?

A

It analyzes performance and detects slow components during interactions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Why should useState types be explicitly defined in some cases?

A

useState may not always infer types correctly, so explicit types ensure type safety.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly