Skip to content

MobxInfiniteQuery

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

See docs for MobxQuery

Usage

Create an instance of MobxInfiniteQuery with queryKey and queryFn parameters

ts
const query = new MobxInfiniteQuery({
  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.