Props Children — Complete Guide
Props Children — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of React.js Tutorial on Toolliyo Academy.
On this page
React.js Tutorial · Lesson 13 of 100
Components
Beginner → Intermediate → Advanced → Professional
Beginner · 1 — Foundations · ~12 min read · Module 2: JavaScript & React Fundamentals
Introduction
This lesson is part of the beginner section. We explain Components slowly, with examples you can copy and run. If something is unclear, read it twice — that is how everyone learns. A component is a function (or class) that returns UI. You use components like HTML tags: ,
Components appears in almost every file you will write. Once it clicks, later lessons (hooks, routing, APIs) become much easier.
When will you use this?
You use this in every component you write from your first app to your tenth year on the job.
- Product pages, login forms, and todo lists all use components, props, and state.
- When a user types in a search box, React state holds the text and filters a list.
Real-world: reusable Toolliyo lesson card
Toolliyo course page shows 40 lessons. One LessonCard component renders title, duration, and progress ring — designers change the card once, all courses update.
Production-style code
function LessonCard({ title, durationMin, completed, onOpen }) {
return (
<button type="button" className="lesson-card" onClick={onOpen}>
<span className="title">{title}</span>
<span className="meta">{durationMin} min</span>
{completed ? <span className="done">✓ Done</span> : <span className="todo">Start</span>}
</button>
);
}
function CourseOutline({ lessons, onSelect }) {
return (
<ul>
{lessons.map(l => (
<li key={l.id}>
<LessonCard {...l} onOpen={() => onSelect(l.id)} />
</li>
))}
</ul>
);
}
What happens in production: Component reuse is why Netflix, Toolliyo, and Amazon ship UI updates in days instead of rewriting HTML on every page.
Lesson example (start here)
Copy this smaller example first. Once it works, compare it with the real-world code above.
function Button({ label, onClick }) {
return <button onClick={onClick}>{label}</button>;
}
function App() {
return (
<div>
<Button label="Save" onClick={() => alert('Saved')} />
<Button label="Cancel" onClick={() => alert('Cancelled')} />
</div>
);
}
Line-by-line walkthrough
| Code | What it means |
|---|---|
function Button({ label, onClick }) { | Defines a function — often a component or event handler. |
return <button onClick={onClick}>{label}</button>; | Sends UI or a value back to whoever called this function. |
} | Closes a block started by { or ( above. |
function App() { | Defines a function — often a component or event handler. |
return ( | Sends UI or a value back to whoever called this function. |
<div> | JSX tag — a UI element or custom component on the page. |
<Button label="Save" onClick={() => alert('Saved')} /> | Defines a function — often a component or event handler. |
<Button label="Cancel" onClick={() => alert('Cancelled')} /> | Defines a function — often a component or event handler. |
</div> | Part of the Components example — read it together with the lines before and after. |
); | Closes a block started by { or ( above. |
} | Closes a block started by { or ( above. |
How it works (big picture)
- Button is defined once and used twice with different props.
- Each component should do one job well.
Do this on your computer
- Create src/components/Greeting.jsx.
- Export the function and import it in App.jsx.
- Use
in App. - Read the real-world section and name which part of the app uses this topic.
- Run the example locally and confirm the same behavior in the browser.
- Change one value in the example (text, initial state, or URL) and predict what will happen before you save.
Experiments — try changing this
- Change text or labels in the example and save — watch the browser update.
- Break the code on purpose (remove a bracket), read the error message, then fix it.
Remember
Components are reusable UI functions. Name them with capital letters: UserCard not userCard. Compose small components into pages.
Common questions
Function vs class components?
Use function components with hooks — that is the modern standard.
How long should I spend on Components?
Until you can explain it in your own words and run the example without looking at the answer. Beginners often need 30–60 minutes per new hook or routing topic; setup lessons may take one afternoon.
What if I get stuck on Components?
Re-read the line-by-line walkthrough, check the browser console for red errors, and compare your code character-by-character with the example. Search the exact error text — someone else had it too.
Where is Components used in real jobs?
See the real-world section above — the same pattern appears in LMS, banking, e-commerce, and SaaS products. Interviewers ask you to explain it using one concrete example from your project or this lesson.