Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 2.3 — Passing Props
React · Example 1 of 3

The props object, read two ways

Each <Greeting /> gets its own props object. The string came from quotes, the number from braces.

Props are the inputs of a component: the parent writes them like attributes, React collects them into one object, and the child reads that object (usually by destructuring) to decide what to show. Any JavaScript value can be a prop: strings, numbers, booleans, objects, arrays, functions and JSX.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 5 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Write a Weather component that receives city (string), temp (number) and sunny (boolean) and shows Pune: 31°C ☀️ or Pune: 24°C ☁️. Render it for two cities.

02

Write a Tags component that receives an array items and shows them joined with · . Render it with three tags.

Explain it without notes

01

What are props, and how does a component receive them?

02

When do you use quotes and when braces for a prop's value?

03

How does a child component tell its parent that something happened?

04

Why do some developers say "props flow down, events flow up"?

The props object, read two ways

Preview

Press Run to see the page.

Console

Nothing logged yet.

Expected console output

Greeting got { name: 'Asha', age: 9 }
Greeting got { name: 'Ravi', age: 11 }