Skip to content

InfiniteQuery

Class wrapper for @tanstack-query/core infinite queries with MobX reactivity

See docs for Query

All documentation about properties and methods of infinite query can be found in the original documentation here

Reference to source code

Usage

Create an instance of InfiniteQuery with queryKey and queryFn parameters

ts
const query = new InfiniteQuery({
  queryClient,
  abortSignal: this.abortSignal,
  queryKey: ['stars']
  queryFn: async ({ signal, pageParam }) => {
    const response = await starsApi.fetchStarsList(
      {
        count: 20,
        page: pageParam,
      },
      {
        signal,
      },
    );

    return response.data;
  },
  initialPageParam: 1,
  onError: (e) => {
    notify({
      type: 'danger',
      title: 'Failed to load stars',
    });
  },
  getNextPageParam: (lastPage, _, lastPageParam) => {
    return lastPage.length ? lastPageParam + 1 : null;
  },
});

Released under the MIT License.