Retry a Failed Load

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

The problem

  • medium
  • Code

The component gets a loadItems prop: a function that takes no arguments and returns a Promise of an array of strings. Call it when the component mounts and show "Loading..." (three full stops) while it runs. When it resolves, show the strings as list items. When it rejects, show an element with role="alert" containing "Couldn't load the list." and a "Try again" button. Try again hides the alert, shows "Loading..." again and calls loadItems once more. The starter's default loadItems fails the first time and works after that, so you can try it in the preview.

Your code must pass

  • Lists the items once they load
  • Shows an alert and Try again when loading fails
  • Try again loads once more and shows the items