TypeScript · Middle · Question 20 of 75
How do you get a native button's props to extend them in your component?
- ✓Correct answer:
React.ComponentProps<'button'> - 2
HTMLButtonElement- the button's props type - 3
React.ButtonPropsfrom the@types/reactpackage
Explanation
type Props = React.ComponentProps<'button'> & { variant: 'primary' | 'ghost' } - the component accepts all native attributes (onClick, disabled, aria-*). HTMLButtonElement is the DOM node type, not props. ComponentProps<typeof MyComp> extracts the props of any component.