Basic Prop Syntax: Passing Values
You'll learn: How to pass data into components using HTML-like attribute syntax.
The Core Pattern
Now that you know what props are (arguments to components), let's see how you actually pass them. React uses a syntax that looks exactly like HTML attributes:
<Greeting name="Alice" />
This passes a prop called name with the value "Alice" to the Greeting component.
How It Works
Think of it like labeling a gift box before handing it to someone. The component name is who receives it, and the attributes are the labeled contents inside.
When you write:
<WelcomeMessage username="Bob" />
You're telling React: "Call the WelcomeMessage component and give it a prop called username with the value 'Bob'."
The Basic Syntax Rules
The pattern is always:
<ComponentName propName="propValue" />
- Component name in PascalCase
- Prop name in camelCase (like regular JavaScript variables)
- String values in quotes
You can pass multiple props by adding more attributes:
<UserCard name="Charlie" age="25" city="Boston" />
Each prop is separated by a space, just like HTML attributes.
Inside the Component
The receiving component gets all these props bundled together as an object (you'll learn how to access them next):
function UserCard(props) {
// props is now { name: "Charlie", age: "25", city: "Boston" }
}
Key Takeaway: Props are passed using HTML-like attribute syntax: <Component propName="value" /> — it's React's way of sending labeled data into components.