What Are Props?
Part of the Fundamentals section of Coddy's React journey — lesson 16 of 42.
Reusing a component is nice, but three identical stars are only so useful. Props let you pass data into a component, so every copy can be different:
function Greeting({ name }) {
return <p>Hello, {name}!</p>;
}
export default function App() {
return (
<div>
<Greeting name="Ada" />
<Greeting name="Alan" />
</div>
);
}Two things happen here:
- Passing: props look like attributes:
name="Ada" - Receiving: the component unpacks them in its parameter list (
{ name }) and uses them in JSX like any variable
Same component, different data, different output: Hello, Ada! and Hello, Alan!. Props are how parents configure their children.
Try it yourself
This lesson doesn't include a code challenge.
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
2JSX Expressions
Curly BracesMath in BracesBraces in AttributesCalling Functions in JSXRecap: JSX Expressions5State & Events
What Is State?Click CounterCount in StepsToggle with StateIndependent StateRecap: State & Events8Project: Profile Card
Step 1: Card StructureStep 2: Card with PropsStep 3: Like ButtonStep 4: Follow Toggle