Day 12 of 14 30 minTyped propsEventsGeneric components
Add TypeScript to React components. Type props and children, state, events and refs, type reducers with discriminated unions, type a context safely, and write generic components that work with any kind of item.
By the end of today you can
- Type component props, optional props and children
- Type useState, useRef and event handlers
- Type a reducer's actions with a discriminated union
- Type a context and its custom hook safely
- Write a generic list component
What's inside
- 5 sections
- 2 diagrams and mind maps
- 4 code examples you can run
- 5-question quiz
- 1Typing props
- 2Typing state, refs and events
- 3Typing a reducer
- 4Typing context
- 5Generic components
Sign in free to read this lesson
Get the full lesson with diagrams, runnable code and the quiz. Your progress is saved across devices.
Sign in free