Components & Props

Props (short for "properties") are how data flows into a component from whoever renders it — the same way arguments flow into a function.

Passing and reading props

Any attribute you write on a component in JSX becomes a property on a single props object the component receives:

JSX App.jsx
function UserCard(props) {
  return (
    <div className="card">
      <h3>{props.name}</h3>
      <p>{props.role}</p>
    </div>
  );
}

function App() {
  return (
    <>
      <UserCard name="Priya" role="Frontend Developer" />
      <UserCard name="Sam" role="Backend Developer" />
    </>
  );
}
Rendered output
Two cards, one reading "Priya / Frontend Developer"
and one reading "Sam / Backend Developer" — the
same UserCard component, rendered twice with
different data.

<UserCard name="Priya" role="Frontend Developer" /> creates a props object {"{ name: 'Priya', role: 'Frontend Developer' }"} and hands it to UserCard. This is the entire point of components: write the markup once, then reuse it with different data every time you render it.

Destructuring props

Writing props.name and props.role repeatedly gets tedious — most real React code destructures the props object right in the function signature:

JSX UserCard.jsx
function UserCard({ name, role }) {
  return (
    <div className="card">
      <h3>{name}</h3>
      <p>{role}</p>
    </div>
  );
}
Rendered output
Identical output to the previous example — this
is purely a more concise way to write the same thing.

Props are read-only

A component must never modify its own props. If UserCard needs to change what it displays, that change has to come from whoever renders it passing different props in — not from UserCard reassigning props.name itself.

Note: this "props are read-only" rule is what makes a component's behavior predictable: given the same props, a component always renders the same thing. If you need a component to manage data that changes over time on its own (like a counter or a text input's current value), that's what state is for — covered in the next lesson.