Lesson 17 of 30
57%
Component Composition
Composition means building big UI from small pieces, the way you nest HTML tags.
React prefers this over class inheritance.
children as a hole in the layout
javascript
Slots with named props
When you have two holes, give them names.
javascript
Containment vs specialization
Do not make WelcomeDialog extend Dialog with inheritance.
Make Dialog wrap children, then:
javascript
Keep props boring
A component that takes 12 flags is trying to be every variant.
Split it. Compose the variants from smaller parts.
Tip: If you are about to write a boolean prop like isHeader, you might want two components instead.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.