[ More update to LoadMoreFn types in custom pagination hooks
@@ -22,6 +22,7 @@ import type {
GraphQLTaggedNode,
Observer,
OperationType,
+ Variables,
} from 'relay-runtime';
const useLoadMoreFunction = require('../useLoadMoreFunction');
@@ -37,8 +38,8 @@ const useRelayEnvironment = require('../useRelayEnvironment');
export type ReturnType<TQuery: OperationType, TKey, TFragmentData> = {
data: TFragmentData,
- loadNext: LoadMoreFn<TQuery>,
- loadPrevious: LoadMoreFn<TQuery>,
+ loadNext: LoadMoreFn<TQuery['variables']>,
+ loadPrevious: LoadMoreFn<TQuery['variables']>,
hasNext: boolean,
hasPrevious: boolean,
isLoadingNext: boolean,
@@ -87,7 +88,7 @@ function usePaginationFragment<
// Backward pagination
const [loadPrevious, hasPrevious, isLoadingPrevious, disposeFetchPrevious] =
- useLoadMore<TQuery>({
+ useLoadMore<TQuery['variables']>({
componentDisplayName,
connectionPathInFragmentData,
direction: 'backward',
@@ -101,8 +102,9 @@ function usePaginationFragment<
});
// Forward pagination
- const [loadNext, hasNext, isLoadingNext, disposeFetchNext] =
- useLoadMore<TQuery>({
+ const [loadNext, hasNext, isLoadingNext, disposeFetchNext] = useLoadMore<
+ TQuery['variables'],
+ >({
componentDisplayName,
connectionPathInFragmentData,
direction: 'forward',
@@ -147,7 +149,7 @@ function usePaginationFragment<
};
}
-function useLoadMore<TQuery: OperationType>(
+function useLoadMore<TVariables: Variables>(
args: $Diff<
UseLoadMoreFunctionArgs,
{
@@ -156,7 +158,7 @@ function useLoadMore<TQuery: OperationType>(
...
},
>,
-): [LoadMoreFn<TQuery>, boolean, boolean, () => void] {
+): [LoadMoreFn<TVariables>, boolean, boolean, () => void] {
const environment = useRelayEnvironment();
const [isLoadingMore, reallySetIsLoadingMore] = useState(false);
// Schedule this update since it must be observed by components at the same
@@ -178,7 +180,7 @@ function useLoadMore<TQuery: OperationType>(
error: () => setIsLoadingMore(false),
};
const handleReset = () => setIsLoadingMore(false);
- const [loadMore, hasMore, disposeFetch] = useLoadMoreFunction<TQuery>({
+ const [loadMore, hasMore, disposeFetch] = useLoadMoreFunction<TVariables>({
...args,
observer,
onReset: handleReset,
