Created
September 13, 2023 11:00
-
-
Save joshuacerbito/ba47f997093c17df0d3ed4bc431b69da to your computer and use it in GitHub Desktop.
Extend or use the props interface/type of any component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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