React Foundations · TypeScript

Reusing a native element's props

ComponentProps

Reusing a native element's props

Wrap a <button> in your own Button and you lose the native props: type, disabled, aria-*, event handlers. You could list them all again, but then you are maintaining a copy of the DOM's own API. ComponentProps hands you that whole prop type instead:

import type { ComponentProps } from 'react';

function Button(props: ComponentProps<'button'>) {
  return <button {...props} />;
}

ComponentProps<'button'> is the type of every valid prop on a <button>. The spread {...props} forwards them all to the real element, so Button supports the full native API:

<Button type="button" aria-label="Greeting">
  Hi
</Button>

Adding a prop later means the native element already knows it — no interface to keep in sync. To keep your own prop as well, intersect the two types:

type ButtonProps = ComponentProps<'button'> & { tone?: 'plain' | 'accent' };

Your job is to reuse a native element's props through ComponentProps in App.tsx.

Challenge

A Button wrapper swallows the props it is given, so the type and aria-label never reach the real button. Export an App component from App.tsx that renders a Button with type="button" and aria-label="Greeting". Give Button the type ComponentProps<'button'> and spread those props onto a native <button> element.

The Test renders your component and expects a button whose type is button and whose aria-label is Greeting. The starter does not forward the props, so the Test fails.

App.tsx
import type { ReactNode } from 'react';

function Button({ children }: { children: ReactNode }) {
  return <button>{children}</button>;
}

export function App() {
  return (
    <Button type="button" aria-label="Greeting">
      Hi
    </Button>
  );
}

No test run yet

The Test is hidden. Run it to check the Challenge — you only see the result, never the test source.