Skip to content

Instantly share code, notes, and snippets.

@joshuacerbito
Created September 13, 2023 11:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshuacerbito/ba47f997093c17df0d3ed4bc431b69da to your computer and use it in GitHub Desktop.
Save joshuacerbito/ba47f997093c17df0d3ed4bc431b69da to your computer and use it in GitHub Desktop.
Extend or use the props interface/type of any component
// extend basic react component props
// simply replace the type and add your props' types
interface PersonCardProps extends React.ComponentProps<typeof PersonCard> {
name: string;
age: number;
isAdmin: boolean;
}
// in this example we're writing a component named PersonCard
// with props name, age, and isAdmin
function PersonCard({ name, age, isAdmin }: PersonCardProps) {
return <p>May name is {name}, {age] years of age, and I'm { !isAdmin && "not " }an admin</p>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment