DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober 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 desk4 min

Props in React: A Beginner’s Introduction

Props are the inputs parents pass to React components. Learn how to pass and read them, set defaults, use children, and distinguish props from state and context.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Props are the values a parent component gives a child component through JSX. A child reads those values to decide what to render; if the parent has different values on a later render, the child receives those instead.

What are props in React?

Props are a component’s inputs, supplied by its parent. They let the same component render different content or behave differently depending on the values it receives. React describes props as similar to function arguments: the parent provides them, and the child uses them.

A prop can hold a string, number, object, array, function, or JSX value. In JSX, you write a prop as an attribute on the component tag.

How do I pass props to a component?

In this example, Profile is the parent. It passes a person object and a size number to Avatar:

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

function Profile() {
  return (
    <Avatar
      person={{ name: 'Lin', imageUrl: '/lin.jpg' }}
      size={80}
    />
  );
}

The parent writes the values on <Avatar ... />; the child receives them when React renders Avatar. Use curly braces in JSX when passing a JavaScript expression, such as an object or number. A string can also be written directly as an attribute, for example <Greeting name="Lin" />.

How do I access props in a function component?

A function component receives one props object as its parameter. Destructuring lets you pull out the properties you need by name:

function Avatar(props) {
  return <img src={props.person.imageUrl} alt={props.person.name} />;
}

This is equivalent to accessing the object’s properties directly. The earlier function Avatar({ person, size }) version uses JavaScript destructuring for convenience; destructuring itself is not special React behavior.

How do default prop values work?

You can give a destructured parameter a default value. Here, the avatar uses a size of 100 if the caller omits size or passes undefined:

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

The default does not apply when the caller passes null or 0; those are actual values, not an omitted or undefined value.

What is children in React?

When a component has nested JSX between its opening and closing tags, React passes that content to it as the children prop. This makes wrapper components such as cards or panels reusable with different contents:

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

function ProfileCard() {
  return (
    <Card>
      <h2>Lin</h2>
      <p>Frontend developer</p>
    </Card>
  );
}

The JSX inside <Card>...</Card> becomes Card’s children, which it can render wherever appropriate.

Should I forward props with spread syntax?

JSX spread syntax can pass an object’s properties along to another component. For example, <Avatar {...props} /> forwards the properties in props to Avatar. This can reduce repetitive forwarding when it is intentional, but use it selectively: passing only the values a component actually needs makes its inputs easier to see. If a component mainly relays information it does not use, consider whether nested JSX and children would express the composition more clearly.

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

How are props different from state and context?

Choose based on who supplies the value, whether the component changes it through interaction, and how far it must travel in the component tree.

Concept Where the value comes from When it fits
Props A parent passes values to a child. Use for explicit inputs a component needs from its parent.
State A component’s own changing memory. Use for information the component updates in response to interaction or other events. A parent can also own state and pass its current value to children as props.
Context An ancestor makes a value available to descendants. Consider it when many descendants need the same information and passing it through intermediate components becomes cumbersome.

Props are inputs, not something a child edits

Props are read-only snapshots for a particular render. A child should not change its props; when a value changes, the parent supplies the new value on a render. React’s Passing Props to a Component guide states: “Props are read-only snapshots in time: every render receives a new version of props.”

Use context for a specific data-flow problem

Ordinary props make the parent-to-child path visible. If the same value must be carried through several intermediate components that do not use it, that explicit forwarding can become verbose; React context can make the value available to descendants without threading it through each layer. Context is an alternative for that situation, not a replacement for straightforward props.

For a broader view of how props and state fit into component design, see React’s Thinking in React guide. React’s Rules of React also explain the expectation that render inputs are treated immutably.

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

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
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver 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.