Skip to the workspace
Pebellslearn by building
Components and JSX  ›  Lesson

Props — Data Flowing Down

Props vs State 14 minProps are the read-only inputs a parent passes to a child component, letting one component show different data each time it is used.

react / Props — Data Flowing Down

Explore each scene at your own pace.

01 · The rule

The rule

Props — Data Flowing Down

Our BookCard from earlier always shows The Hobbit. A card that can only ever show one book is not much of a component. Props are how a parent says, "this time, show this."

The rule

Props flow down, arrive as one object, and are read-only.

Flow down. A parent passes props to a child by writing attributes on the child's tag:

export default function App() {
  return (
    <main>
      <BookCard title="The Hobbit" author="J. R. R. Tolkien" pages={310} />
      <BookCard title="Dune" author="Frank Herbert" pages={412} />
    </main>
  );
}

Strings can use quotes. Anything else — numbers, booleans, arrays, objects, functions — goes in braces: pages={310}, read={true}. Writing just read is shorthand for read={true}.

One object. The child receives every prop in a single object, its first parameter. Destructuring pulls out the ones you need, and you can give defaults:

function BookCard({ title, author, pages = 0 }) {
  return (
    <article className="book">
      <h2>{title}</h2>
      <p>{author} · {pages} pages</p>
    </article>
  );
}

Read-only. A component must never change its own props. title = title.toUpperCase() inside BookCard breaks the rule. Props belong to the parent; the child only reads them. If data needs to change over time, that is a job for state, which you meet in the State section. In one line: props are handed to you; state is kept by you.

Props can carry anything, including functions. <BookCard onRemove={handleRemove} /> gives the child a function it can call to tell the parent something happened — the only way information travels back up. And when the parent re-renders with different props, the child simply re-renders with the new values; nothing needs to be copied or synced.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.