Module 32: Components and Props

Lesson 1 of 5 · 15–25 minutes

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

<EnquiryCard name="Asha" subject="Course fees" />
interface EnquiryCardProps {
  name: string;
  subject: string;
}

export function EnquiryCard({ name, subject }: EnquiryCardProps) {
  return (
    <article className="card">
      <h3>{name}</h3>
      <p>{subject}</p>
    </article>
  );
}

🖱️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).

← BackModule 32
ProLearners Assist