Код IT
← Каталог

TypeScript и React — Компонент и `props`

Фрагмент из «TypeScript и React»: Компонент и `props`.

Plain text main.tsx
type CardProps = {
  title: string;
  subtitle?: string;
  children?: React.ReactNode;
};

function Card({ title, subtitle, children }: CardProps) {
  return (
    <section className="card">
      <h2>{title}</h2>
      {subtitle ? <p>{subtitle}</p> : null}
      {children}
    </section>
  );
}
type CardProps = {
  title: string;
  subtitle?: string;
  children?: React.ReactNode;
};

function Card({ title, subtitle, children }: CardProps) {
  return (
    <section className="card">
      <h2>{title}</h2>
      {subtitle ? <p>{subtitle}</p> : null}
      {children}
    </section>
  );
}