Props5 / 12
Up next

Optional props

interface AvatarProps {
  src: string;
  alt?: string;
}

// alt may be undefined, so provide a fallback
function Avatar({ src, alt }: AvatarProps) {
  return <img src={src} alt={alt ?? "avatar"} />;
}

export default Avatar;
What you're solving

mark props optional and handle the missing case