Load More Results

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

The problem

  • medium
  • Code

Build a list that loads a page at a time. The loadPage prop takes a page number, starting at 1, and returns a Promise of { items, hasMore }: an array of strings, and whether there's another page after it. Load page 1 when the component mounts and show every loaded item as a list item, in order. Below the list, a button reads "Load more"; clicking it loads the next page and adds its items after the others. Whenever a page is loading (the first one too) the button is disabled and reads "Loading..." (three full stops). Once a page comes back with hasMore false, remove the button.

Your code must pass

  • Loads page 1 and lists its items
  • The button reads "Loading..." and is disabled while a page loads
  • Load more adds the next page below
  • The button goes away after the last page