Passing props
You have a greeting that works. Now you want it to greet different people. If the name is baked into the component, you would copy the whole thing for every name. Components become reusable when they can take props — inputs passed in from the outside.
In JSX you pass a prop like an HTML attribute:
<Greeting name="Ada" />
React collects those attributes into a single object and hands it to the component as its first argument. Destructuring that object in the parameter list is the idiomatic way to read the props you need:
export function Greeting({ name }) {
return <p>Hello, {name}!</p>;
}
Props are read-only: a component must never reassign them. They flow one way, from parent to child, which is what makes a component's output predictable from its inputs.
The destructuring pattern names the props the component reads, so the call site shows what it needs. Naming only those props keeps the component reusable.
Your job is to read a prop and render it.
Challenge
A greeting is stuck saying Hello! no matter who it is for. Export an App
component from App.jsx that accepts a name prop and renders a paragraph
reading Hello, <name>! — for Ada, that is Hello, Ada!.
The Test renders <App name="Ada" /> and reads the paragraph's text. The starter
ignores props and always prints Hello!, so the Test fails — take the name
prop and drop it into the greeting.