Module 32: Components and Props
Props
🏠The everyday picture
A name-badge printer: the same badge design, but each badge gets a different name and role fed in. Props are what you feed into a component.
📘What it really is
- Props (properties) are values passed into a component, like arguments to a function:
<EnquiryCard name="Asha" subject="Course fees" />
- The component receives them as one object, usually unpacked straight away:
interface EnquiryCardProps {
name: string;
subject: string;
}
export function EnquiryCard({ name, subject }: EnquiryCardProps) {
return (
<article className="card">
<h3>{name}</h3>
<p>{subject}</p>
</article>
);
}
-
With TypeScript, the props interface documents exactly what the component needs. Missing or wrong props are errors, before you run anything.
-
Pass text in quotes; anything else in braces:
count={3},isUrgent={true},enquiry={enquiry}. - Props are read-only. A component must never change its own props; it only reads them.
🖱️Try it
Change EnquiryCard to take name, subject, status and createdAt as props. In Dashboard, pass different
values to three cards. Leave out a prop on purpose and read the TypeScript error.
✅Quick check
How is passing props like calling a function?
Show the answer
Props are the component's inputs, like a function's arguments.
Can a component change its own props?
Show the answer
No. Props are read-only; changing data uses state (Module 33).
