Command Palette

Search for a command to run...

Hectal
Phase 2: Components and Props
React · Exercise 3 of 5 PreviousNext
Beginner

A Button wrapper with defaults and rest props

Rewrite Button so it takes a variant prop that defaults to "primary", plus children, and collects every other prop with ...rest.

It must render a real <button> whose className is btn btn-<variant> (for example btn btn-danger) and spread the rest props onto it, so id, onClick, disabled and any other attribute just work.

Don't change App: it already uses Button the way a real app would. When it works, clicking Save shows Saved! in the paragraph #msg.

What Check tests

  1. Save has the classes btn btn-primary (the default variant)
  2. Delete has btn-danger and keeps its title
  3. Undo is disabled and has btn-ghost
  4. Clicking Save shows Saved!
  5. variant is never written onto the DOM

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.