Skip to content
Discussion options

You must be logged in to vote

Is the filtering done on the client ? (.filter())

Sounds like you could use the useInfiniteQuery to handle this, with an effect to handle the situation of less than 20 items.

On the effect, you would look if there are less than 20 items, and if there is a next page before fetching the next page.

Something like:

const { data, hasNextPage, fetchNextPage } = useInfiniteQuery(...) // Use the hook correctly with getNextPageParam

if (!data) return null;

const filteredItems = data.pages.flat().filter(...)

useEffect(function maybeFetchMoreItems() {
  if (filteredItems.length < 20 && hasNextPage) {
    fetchNextPage();
  }
  
}, [filteredItems, hasNextPage])

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@DorSarel
Comment options

@julionav
Comment options

@DorSarel
Comment options

Answer selected by DorSarel
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