Home

Component props

  1. Extend props of an HTML element with custom props
import { ComponentProps } from "react";
type ButtonProps = ComponentProps<"button"> & {
  size: "small" | "default"
};
  1. Infer prop types from the definition of a component
const SubmitButton = (props: { onClick: () => void }) => {
  return <button onClick={props.onClick}>Submit</button>;
};
type SubmitButtonProps = ComponentProps<
  typeof SubmitButton
>;

Source