fix: infinite query hook reset

This commit is contained in:
MTG2000
2022-05-20 16:06:28 +03:00
parent 80c9e31467
commit 4e307e071e
4 changed files with 22 additions and 13 deletions

View File

@@ -1,4 +1,5 @@
import { QueryResult } from "@apollo/client";
import { useUpdateEffect } from "@react-hookz/web";
import { useCallback, useState } from "react";
export const useInfiniteQuery = (query: QueryResult, dataField: string) => {
@@ -6,6 +7,10 @@ export const useInfiniteQuery = (query: QueryResult, dataField: string) => {
const [reachedLastPage, setReachedLastPage] = useState(false)
const variablesChanged = () => {
setReachedLastPage(false);
}
const fetchMore = useCallback(
() => {
if (!fetchingMore && !reachedLastPage) {
@@ -28,6 +33,7 @@ export const useInfiniteQuery = (query: QueryResult, dataField: string) => {
return {
isFetchingMore: fetchingMore,
fetchMore: fetchMore
fetchMore: fetchMore,
variablesChanged // Call this function whenever other query vars beside take/skip changes.
}
}