Skip to content

Can hyper do infinite fetching? #116

Answered by prc5
npearson72 asked this question in Q&A
Discussion options

You must be logged in to vote

Our approach in this case is similar to the SWR's approach with making micro components:

function Page({ offset }) {
  const { data, error, loading } = useFetch(getList.setQueryParams({ offset }));

  return (
    <div>
      {data.map((element) => (
        <div>{element}</div>
      ))}
    </div>
  );
}

function Component() {
  const [page, setPage] = useState(1);

  const loadMore = () => {
    setPage((page) => page + 1);
  };

  return (
    <div>
      {Array.from(Array(page).keys()).map((key) => (
        <Page key={key} offset={key * 10} />
      ))}
      <button onClick={loadMore}>Load More</button>
    </div>
  );
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@npearson72
Comment options

Answer selected by prc5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants