AI Hints
Home›React Tutorial›Children and Defaults
React · Lesson 10 of 120

children

Wrapping content.

⏱ 2 min read▶ Video at 7:12🎓 Free
Watch this lesson in the React courseWatch on YouTube ↗Full React course

Sometimes a component wraps other content, like a card or a panel. Whatever you put between its tags arrives in a special prop, called children.

  • Wrapper components
  • Content between tags
  • children

A Panel component

Panel draws a box with a title, and puts its children inside. App fills two panels with completely different content. Run it.

App.jsxjsx
function Panel({ title, children }) {
  return (
    <div className="box">
      <h2>{title}</h2>
      {children}
    </div>
  );
}

export default function App() {
  return (
    <>
      <Panel title="Opening hours"><p>Mon to Sat, 9 to 6</p></Panel>
      <Panel title="Delivery"><p>Free from £50</p><p>Next day: £9.99</p></Panel>
    </>
  );
}
Also uses style.css
body{font-family:-apple-system,Helvetica,Arial,sans-serif;margin:22px;font-size:21px;color:#1d1d1f;background:#fafafa}
h1{font-size:34px;margin:0 0 14px} h2{font-size:26px;margin:0 0 10px}
button{font-size:19px;padding:9px 18px;border-radius:9px;border:0;background:#61dafb;color:#111;font-weight:600;margin:4px 6px 4px 0}
input{font-size:19px;padding:8px 10px;border:2px solid #bbb;border-radius:8px}
li{margin:5px 0} .box{padding:14px;border-radius:12px;background:#fff;border:2px solid #ddd;margin:8px 0}
.done{text-decoration:line-through;color:#999} small{color:crimson;display:block;font-size:16px} .big{font-size:64px;font-weight:800}

Summary

Children holds whatever sits between a component's tags, so components can wrap anything. Next, default values.

Key takeaways
  • { children }
  • Wrappers
  • Any content
Next up: Default Values — sensible defaults