DEV Community

Cover image for Passing Children as Props in React (Beginner Friendly Guide)
Ahmad Mahboob
Ahmad Mahboob

Posted on • Originally published at ahmadcodes.hashnode.dev

Passing Children as Props in React (Beginner Friendly Guide)

When you start learning React, you often hear about props. Props help us pass data from one component to another.

But there is one special prop in React that beginners usually find confusing — children.

In this blog, we’ll understand:

  • What children is in React

  • Why we use it

  • How to pass children as props

  • Simple examples you can understand easily

No advanced concepts. Just clear basics.


What Are Children Props in React?

In React, children is a special prop that allows you to pass JSX or content inside a component, instead of passing it as a normal prop.

Simple meaning:

Whatever you write between the opening and closing tag of a component becomes children.

Example:

<Card>
  <h2>Hello World</h2>
</Card>
Enter fullscreen mode Exit fullscreen mode

Here, <h2>Hello World</h2> is the children of the Card component.


Why Do We Use Children Props?

Children props are useful when:

  • You want to create reusable components

  • You don’t know in advance what content will go inside a component

  • You want to keep components flexible and clean

Think of it like a container or wrapper that can hold different content.


Basic Example of Children Props

Let’s start with a very simple example.

Parent Component

function App() {
  return (
    <Box>
      <p>This is inside the Box</p>
    </Box>
  );
}
Enter fullscreen mode Exit fullscreen mode

Child Component

function Box({ children }) {
  return (
    <div style={{ border: "2px solid black", padding: "10px" }}>
      {children}
    </div>
  );
}
Enter fullscreen mode Exit fullscreen mode

What’s Happening Here?

  • Box is a component

  • Whatever we write inside <Box>...</Box> becomes children

  • {children} renders that content inside the component


Children Can Be Anything

Children are not limited to text only. They can be:

Text

<Card>Welcome</Card>
Enter fullscreen mode Exit fullscreen mode

HTML / JSX

<Card>
  <h3>Title</h3>
  <p>Description</p>
</Card>
Enter fullscreen mode Exit fullscreen mode

Components

<Card>
  <Button />
</Card>
Enter fullscreen mode Exit fullscreen mode

React treats all of this as children.


Real-World Use Case (Very Common)

Imagine a Button component:

function Button({ children }) {
  return (
    <button className="btn">
      {children}
    </button>
  );
}
Enter fullscreen mode Exit fullscreen mode

Usage:

<Button>Login</Button>
<Button>Sign Up</Button>
Enter fullscreen mode Exit fullscreen mode

Instead of creating multiple buttons, you reuse one component and pass different text using children.


Children vs Normal Props

Using Normal Props

<Button text="Login" />
Enter fullscreen mode Exit fullscreen mode

Using Children

<Button>Login</Button>
Enter fullscreen mode Exit fullscreen mode

Why Children Is Better?

  • More readable

  • More flexible

  • Can pass complex JSX, not just text


Common Beginner Mistakes

Here are some common mistakes beginners make:

  1. Forgetting to render {children} inside the component

  2. Thinking children is a keyword (it’s just a prop)

  3. Using self-closing tags when children are needed

    <Box />

    <Box>Content</Box>

  4. Confusing children with normal props


When Should You Use Children?

Use children when:

  • You are building reusable UI components

  • Your component is acting as a wrapper or layout

  • Content inside the component can change

Do not use children when the component has a fixed structure.


Final Thoughts

Children props are one of the most powerful and simple features of React.

Once you understand them, writing clean and reusable components becomes much easier.

If you are serious about React, mastering children is not optional — it’s essential.

Keep practicing small examples. That’s how React really clicks.

Important Links

Quick Start – React

CSS Modules in React: Scoped Styling Without the Headache

How to Add Tailwind CSS to a React App (Step-by-Step Guide)

How to Use Bootstrap in a React Project (Beginner Guide)

What Are Props in React? A Beginner-Friendly Guide

Conditional Rendering in React: A Practical Guide for Beginners

How to Use map() in React (With Simple Examples)

How to Create a React App Using Vite (Step-by-Step Guide for Beginners)

Understanding React Project Structure Created by Vite (Beginner’s Guide)

React Fragments Explained: How to Group Elements Without Extra DOM Nodes

React Components Explained: A Beginner-Friendly Guide with Examples

Top comments (0)