Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk3 min

How to Pass Props to Child Components in React

Pass values to React children through named JSX props, compose nested content with children, and keep changing data in the component that owns it.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Pass values to a child by adding named props to its JSX element, then read them from the child component’s props object. Props can hold strings, numbers, objects, arrays, or functions—not just text.

Pass a value from a parent to a child

Put each value on the child’s JSX element using a prop name. Use braces to pass a JavaScript value such as a variable, number, object, array, or function.

As an Amazon Associate I earn from qualifying purchases.

function Avatar({ person, size = 100 }) {
  return (
    <img
      src={person.imageUrl}
      alt={person.name}
      width={size}
      height={size}
    />
  );
}

function Profile({ person }) {
  return <Avatar person={person} size={80} />;
}

Here, Profile passes the person object and the number 80 to Avatar. The child receives them together in one props object. Its parameter can name that object or destructure the values directly. React’s Passing Props to a Component guide describes props as information passed to a JSX tag.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
function Avatar(props) {
  return <img src={props.person.imageUrl} alt={props.person.name} />;
}

// Equivalent access with destructuring:
function Avatar({ person }) {
  return <img src={person.imageUrl} alt={person.name} />;
}

Choose explicit props for direct data handoffs

For a direct parent-to-child relationship, use named props and pass only what the child needs. Explicit names make the data flow visible at the place where the child is rendered, and help the components be understood independently.

Props can carry functions as well as data. A parent can pass a callback when the child needs to request an action; the parent can then update the state it owns and render again with updated values.

function SaveButton({ onSave }) {
  return <button onClick={onSave}>Save</button>;
}

function Editor() {
  function saveChanges() {
    // Save or update data owned by this component.
  }

  return <SaveButton onSave={saveChanges} />;
}

Use children to compose nested JSX

When JSX is nested between a component’s opening and closing tags, the component receives that content through the children prop. This is useful for visual wrappers such as cards, panels, or layout components that should not need to know the details of everything inside them.

function Card({ children }) {
  return <div className="card">{children}</div>;
}

function Profile({ person }) {
  return (
    <Card>
      <Avatar person={person} />
    </Card>
  );
}

In this example, Card renders the nested Avatar through {'{children}'} without needing to know what component it contains. See React’s guide to passing props and rendering nested content.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Set defaults and forward props deliberately

Provide a fallback for missing values

Destructuring can assign a default when a prop is missing or has the value undefined:

function Avatar({ person, size = 100 }) {
  // size is 100 if the caller omits it or passes undefined.
}

The default does not replace an explicit value such as 0 or null; it applies when the value is absent or undefined. React documents this pattern in its props guide.

Use prop spreading only when forwarding everything is intentional

You can forward a props object with JSX spread syntax, as in <Avatar {...props} />. Use this when the component is deliberately passing through the entire set. If many components repeatedly forward the same props, consider whether the components should be split or whether nested JSX composition would express the relationship more clearly.

Keep changing data in the component that owns it

Props are inputs to a component, not storage for the child to change. Do not mutate a received prop. When an interaction changes data, update the state that owns that data; React can then render the parent and pass the new value down as props. The React props guide covers passing data, and React’s state-sharing guide explains how components coordinate through shared state.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Use context when explicit forwarding gets in the way

Passing props directly is generally clearest when the parent and child are related and the intermediate components either use the value or make the flow easier to understand. If a value must travel through several components that do not use it, or many descendants need the same information, context can make it available across a subtree without forwarding it at every level.

Context is not an automatic replacement for props. Decide based on how many components need the value, whether intermediary components use it, and whether explicit props still make the data flow easy to follow. React’s context guide explains the trade-off and cautions against overusing context.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.