Lesson 2 of 15
Passing Children (The `children` prop)
Lesson Updated: Apr 28, 2026
Requirement
Understand how to create wrapper components (like a Card or Layout component) that wrap around other elements using the special children prop.
Assignments (Start First)
- Simple beginner UI task: Create a
CardWrappercomponent that accepts achildrenprop and renders it inside a<div>with a border and padding. - Slightly improved version: Add an optional
titleprop toCardWrapper. If provided, render an<h3>at the top of the card before the children. - Practical real-world component: Build a
ModalOverlaycomponent that dims the background and centers whatever content is passed inside it as children. - "The Escalation": Create a
SplitLayoutcomponent that takes two specific props:leftContentandrightContent(which can both accept JSX). Render them side-by-side using Flexbox.
Lessons (Optional)
- The
childrenprop: A special prop automatically passed to components that have opening and closing tags. - Wrappers: Useful for defining consistent layout patterns or styling containers without repeating CSS.
The Summary and Quizzes
- Concept explanation: The
childrenprop lets you nest components inside each other just like standard HTML tags. - Why it works in React: React treats anything between a component's opening and closing tags as a special
childrenproperty inside thepropsobject. - Challenge question: How do you access the content nested inside
<MyWrapper>Hello World</MyWrapper>within theMyWrappercomponent definition?