Command Palette

Search for a command to run...

Hectal
Phase 12: TypeScript with React
React · Exercise 2 of 5 PreviousNext
Beginner

A Button with variants and native props

Finish the Button component so it accepts **every native <button> prop** plus a variant of "primary" or "danger" (default "primary").

Type it with ComponentProps<"button"> joined to your own props, and spread the remaining props onto the real <button>.

The rendered button's class must be btn btn-primary or btn btn-danger. The Add button (id="add") increases the number in id="count"; the Reset button (id="reset") is a danger button that sets it back to 0; the Locked button (id="locked") is disabled.

What Check tests

  1. The three buttons have ids add, reset and locked
  2. Classes are btn btn-primary and btn btn-danger
  3. Clicking Add twice shows 2
  4. Reset sets the count back to 0
  5. The Locked button is disabled
  6. Props are typed with ComponentProps<"button"> and a variant union

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Your page

Press Run to see the page.

Console

Nothing logged yet.