Component Composition
Composition means building bigger components out of smaller ones. React passes whatever you nest inside a component through the special children prop.
A wrapper component can render its children inside a frame, so the same wrapper works with any content.
- children holds the nested JSX
- This keeps wrappers generic and reusable
- Prefer composition over deeply configurable single components
function Card({ children }) {
return <div className="card">{children}</div>;
}
Composition avoids copying layout code. One frame can hold many kinds of content.
Try it yourself
Loading editor…