Command Palette

Search for a command to run...

Hectal
Phase 11: Styling React Apps
React · Exercise 4 of 5 PreviousNext
Intermediate

Write cn() and fix the button overrides

The Button joins its base classes with the caller's className, so the overrides on Delete (id="danger") and Wide (id="wide") don't work: the base bg-teal-600 and px-4 still win.

Write twMerge(classes): split the string, and when two classes have the same group (use the provided groupOf), keep only the last one, preserving order otherwise. Then write cn(...inputs) that joins truthy inputs (strings, or objects like { "opacity-50": disabled }) and passes the result through twMerge.

Use cn(base, className) in Button. The CSS tab stands in for Tailwind's generated CSS.

What Check tests

  1. Save keeps all its base classes
  2. Delete has bg-rose-600 and not bg-teal-600
  3. Delete really is rose-coloured
  4. Wide has px-6 and not px-4, and keeps py-2
  5. No stray spaces or empty classes in Save's className
  6. cn handles an object input

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.