Part 02 / Topic 1 of 7
A prop is just a function argument
A component only ever takes one argument: an object, conventionally called props. Part 1's ProfileCard already destructured it in the parameter list - { name, role, monthlySalary } - rather than writing props.name, props.role everywhere. That is the normal way to write a component in this course and almost everywhere else; props.whatever style is legal but reads worse once a component has more than one or two props.
Real-world example: calling a component is calling a function with one object argument - nothing more:
function add(a, b) {
return a + b;
}
add(2, 3); // 5
function Greeting({ name }) {
return <p>Namaste, {name}!</p>;
}
<Greeting name="Asha" />; // JSX sugar for Greeting({ name: "Asha" })
The right-hand side, <Greeting name="Asha" />, compiles (Part 1, section 5) to a call that eventually passes { name: "Asha" } as Greeting's one argument. Every attribute written on a JSX tag becomes one key on that same object.
Done here? The practice set for Part 2 — including the solutions — is on the part page.