🇬🇧 Limited Time — UK Only·🎓 Free Learning for 1 Month·🤖 Free AI Training Included·📚 4,000+ Lessons · 35,000+ Quizzes·🏆 GCSE Mocks · Olympiad Papers·⚡ Selected Students Only · Limited Places·🎁 Free Value Worth £2,000·🇬🇧 Limited Time — UK Only·🎓 Free Learning for 1 Month·🤖 Free AI Training Included·📚 4,000+ Lessons · 35,000+ Quizzes·🏆 GCSE Mocks · Olympiad Papers·⚡ Selected Students Only · Limited Places·🎁 Free Value Worth £2,000·🇬🇧 Limited Time — UK Only·🎓 Free Learning for 1 Month·🤖 Free AI Training Included·📚 4,000+ Lessons · 35,000+ Quizzes·🏆 GCSE Mocks · Olympiad Papers·⚡ Selected Students Only · Limited Places·🎁 Free Value Worth £2,000·
⚛️ React JS

Props and children

📚 What are Props? Props (properties) are the inputs that a parent passes to a child component. They are read-only inside the child. Any JavaScript value can be a prop: strings, numbers, arrays, objects, functions, even other components. The special children prop holds whatever JSX is placed betwee…

8 min 10 XP Lesson 9 of 23
Props and children
🌐

Appy Says…

Props are how React components communicate. Without props, every Button would look the same and every Card would show the same content. With props, one component becomes endlessly flexible.

📖

What are Props?

Props (properties) are values passed from a parent component to a child component. They're read-only in the child — props flow down, never up.

  • Pass: <Button label="Save" disabled={false} onClick={handleSave} />
  • Receive: function Button({ label, disabled, onClick }) { ... }
  • Or as an object: function Button(props) { return <button>{props.label}</button> }
  • children: content nested inside tags: <Card><p>Content</p></Card>
  • Receive children: function Card({ children }) { return <div>{children}</div>; }
  • Default values: function Button({ label = 'Click me' }) { ... }
🎮

Think of it like Roblox tool settings

When you place a Roblox tool in a game, you configure it — speed, damage, sound. Props are those configuration values. Each time you use a component, you pass different props to configure its appearance and behaviour.

⚙️

How It Works

  • 1. Parent passes props as JSX attributes: <UserCard name={user.name} avatar={user.img} />
  • 2. Child destructures from the props parameter: function UserCard({ name, avatar }) { ... }
  • 3. Props are read-only in the child — never do props.name = 'new'
  • 4. Any JS value can be a prop: string, number, boolean, function, object, React element
  • 5. children is a special prop — content between the opening and closing tags
  • 6. Spread props: <Button {...buttonProps} /> — passes all keys as individual props
🌍

Real-World Examples

  • <Avatar src={user.photo} size={40} alt={user.name} />
  • <Modal title="Confirm"><p>Are you sure?</p></Modal> — children pattern
  • <Button variant="danger" onClick={handleDelete}>Delete</Button>
  • React Router's <Link to="/home">Home</Link> uses both props and children
💡

Key Facts

  • Props are immutable in the child — only the parent can change what it passes
  • children can be any JSX — text, elements, even other components
  • TypeScript adds prop type safety with interfaces: interface ButtonProps { label: string; onClick: () => void; }
  • Prop drilling (passing props through many layers) is solved by React Context or state managers
⚠️

Watch Out!

Never modify props inside a component. Props are read-only by design — mutating them causes unpredictable bugs because React's rendering model assumes props are immutable inputs. If you need local change, copy the value into state first.

📌

Remember

Props flow down from parent to child. They're read-only. Use children for composable wrapper components. Destructure in the function signature for clean code.

What You Learned

  • Props pass data from parent to child as JSX attributes
  • Destructure in function params; children prop wraps nested content
  • Unlocks: reusable, configurable components — the foundation of React architecture

Key Facts

  • Props are immutable in the child — only the parent can change what it passes
  • children can be any JSX — text, elements, even other components
  • TypeScript adds prop type safety with interfaces: interface ButtonProps { label: string; onClick: () => void; }
  • Prop drilling (passing props through many layers) is solved by React Context or state managers

Real-World Examples

• <code>&lt;Avatar src={user.photo} size={40} alt={user.name} /&gt;</code> • <code>&lt;Modal title="Confirm"&gt;&lt;p&gt;Are you sure?&lt;/p&gt;&lt;/Modal&gt;</code> — children pattern • <code>&lt;Button variant="danger" onClick={handleDelete}&gt;Delete&lt;/Button&gt;</code> • React Router's <code>&lt;Link to="/home"&gt;Home&lt;/Link&gt;</code> uses both props and children

Remember

Props flow down from parent to child. They're read-only. Use children for composable wrapper components. Destructure in the function signature for clean code.

Quick Quiz

1 / 2

children is?