Components need data
AUserCard that always shows “Sarah Chen” isn’t useful. Props let you pass different data to the same component, making it reusable.
How props work
Props are passed as attributes in JSX and received as an object parameter:Destructuring props (preferred)
Instead ofprops.name, props.age, destructure in the parameter:
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 thechildren 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 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:Spreading props
When you need to pass many props, spread them: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