0Pricing
TypeScript Academy · Lesson

Generic Components and forwardRef

Build reusable typed components with generics.

Welcome

This lesson covers Generic Components And Forwardref in TypeScript with React.

Component Props Interface

Define a props interface for React components to document and enforce the component API.
interface ButtonProps {
  label: string;
  onClick: () => void;
  disabled?: boolean;
}

function Button({ label, onClick, disabled }: ButtonProps) {
  return <button onClick={onClick} disabled={disabled}>{label}</button>;
}

All lessons in this course

  1. Typing React Component Props
  2. Typing useState and useReducer
  3. Typing useRef and Event Handlers
  4. Generic Components and forwardRef
← Back to TypeScript Academy