Skip to main content

Components need data

A UserCard that always shows “Sarah Chen” isn’t useful. Props let you pass different data to the same component, making it reusable.
Props are to React components what arguments are to functions. Same component, different data, different output.

How props work

Props are passed as attributes in JSX and received as an object parameter:

Destructuring props (preferred)

Instead of props.name, props.age, destructure in the parameter:
This is the standard pattern in React. You’ll see it in almost every component.

What you can pass as props

Anything that’s a valid JavaScript value:
Strings use quotes: name="Sarah". Everything else uses curly braces: age={28}, isAdmin={true}, items={[1,2,3]}. This is because {} is how you embed JavaScript in JSX.

Default props

Use default parameter values for props that are optional:

The children prop

Content between opening and closing tags becomes the children prop:
children is how you build wrapper/layout components. The parent decides the structure, the child provides the content.

Common layout pattern

Props are read-only

Components must never modify their props. Props flow down from parent to child. A child can read them but not change them.
Props are read-only. If a component needs to change data, it should use state (with useState). Props are for passing data down; state is for managing data that changes.

Props vs state

Think of it like a function: props are the arguments passed in, state is the local variables inside.

Passing props down multiple levels

Props flow from parent → child → grandchild:
If you find yourself passing props through many levels (prop drilling), it’s a sign you might need to restructure your components or use React Context. For now, 2-3 levels of prop passing is perfectly fine.

Spreading props

When you need to pass many props, spread them:
Useful when passing API data directly to a component.

What’s next?

Props let you pass data into components. But what about data that changes over time — form inputs, toggle states, fetched data? That’s what state is for.

Managing state with useState

Add interactive, dynamic data to your components