React with TypeScript

Test your understanding of typing components,props,and hooks in React.

1. What are the primary ways to define props for a TypeScript React component?
2. Which React hooks require explicit typing in TypeScript?
3. TypeScript can infer the state type for useState if the initial value is provided.
4. What is the TypeScript type for a button click event handler's event object? (format: React.XyzEvent<...>)
5. How do you define optional props in TypeScript?
6. Which are valid return types for a TypeScript React functional component?
7. React.FC automatically includes the 'children' prop by default.
8. What utility type makes all properties of a type optional? (TypeScript keyword)
9. What is the correct way to type a ref for an input element?
10. Which are benefits of using TypeScript with React?
11. Class components in TypeScript use React.Component<Props, State> to type props and state.
12. What interface/type is used to define the props of a functional component with no props? (e.g., () => <div />)
13. What is the difference between interface and type alias for props?
14. Which TypeScript types are valid for React children?
15. Using 'any' for props is recommended in TypeScript React to save time.
16. What is the abbreviation for the TypeScript utility type that makes all properties required?
17. How do you type a state that can be either a string or null?
18. What are valid ways to handle default props in TypeScript React?
19. React event handlers must always specify the event type to avoid 'any'.
20. What is the TypeScript type for the context value returned by createContext?
Answered 0 of 0 — 0 correct