Curly Braces for Non-String Values
You'll learn: How to pass JavaScript values that aren't strings as props by wrapping them in curly braces.
Why Curly Braces Matter
You already know that props let you pass data to components. When passing a string, you can use quotes directly:
<Greeting name="Alice" />
But what if you want to pass a number, a boolean, an array, or an object? You need curly braces to tell React "this is JavaScript, not a string."
Think of curly braces as an escape hatch: they let you step out of JSX's text mode and write actual JavaScript expressions.
Passing Different Value Types
Numbers:
<Product price={29.99} quantity={5} />
Booleans:
<Button disabled={true} isPrimary={false} />
Arrays:
<ShoppingList items={['Milk', 'Eggs', 'Bread']} />
Objects:
<User profile={{ name: 'Alice', age: 30 }} />
Variables:
const userAge = 25;
<Profile age={userAge} />
The Double-Curly Pattern
When you see {{}}, don't panic—it's just an object literal inside JSX curly braces:
<Card style={{ color: 'blue', margin: 10 }} />
// ^outer: JSX escape ^inner: object literal
Analogy
Think of quotes as a sealed envelope containing only text. Curly braces are like a package that can hold anything—numbers, lists, even other packages (objects).
Key Takeaway: Use curly braces {} whenever you pass non-string values as props—numbers, booleans, arrays, objects, or variables all require them to be treated as JavaScript rather than text.