TypeScript · Middle · Question 20 of 75

How do you get a native button's props to extend them in your component?

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.

Further reading

Problem with a question

TypeScript · Middle · question 20

Test yourself

Take the TypeScript · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz