Show Copied for a Moment

Write the code, see it run, pass the checks.

The problem

  • easy
  • Code

Build a "Copy" button for a short piece of text. Props: text, the text to copy, shown in a paragraph above the button (default "https://www.hone.sh"); copy, a function that takes the text and returns a Promise (in a real app it would call the clipboard; the default just waits 200 milliseconds); and resetAfter, in milliseconds (default 2000). Clicking the button calls copy(text). Once that Promise resolves, the button reads "Copied!"; if it rejects, "Copy failed". Either way it goes back to "Copy" after resetAfter milliseconds. The checks use a resetAfter of 100.

Your code must pass

  • Clicking Copy calls copy with the text
  • Shows "Copied!" only after copying succeeds, then "Copy" again
  • Shows "Copy failed" when copying fails, then "Copy" again