Hook React Query pour exécuter une requête paginée avec Meteor.
export const useInfiniteQueryHook = (name: string, args: MethodArgs = {}, key: QueryKey = [], config: InfiniteQueryHookConfig) => { return useInfiniteQuery({ queryKey: [name, ...key], queryFn: async ({ pageParam }) => { if (Meteor.settings.public.debug === true) { console.log("query - Meteor.call ", name, args); } return Meteor.callAsync(name, pageParam) .then((result) => { if (typeof config.onSuccess === "function") { config.onSuccess(result); } return result; }) .catch((err) => { if (typeof config.onError === "function") { config.onError(err); } throw err; }); }, ...defaultConfig, ...config, throwOnError: false, initialPageParam: args, });}; Copy
export const useInfiniteQueryHook = (name: string, args: MethodArgs = {}, key: QueryKey = [], config: InfiniteQueryHookConfig) => { return useInfiniteQuery({ queryKey: [name, ...key], queryFn: async ({ pageParam }) => { if (Meteor.settings.public.debug === true) { console.log("query - Meteor.call ", name, args); } return Meteor.callAsync(name, pageParam) .then((result) => { if (typeof config.onSuccess === "function") { config.onSuccess(result); } return result; }) .catch((err) => { if (typeof config.onError === "function") { config.onError(err); } throw err; }); }, ...defaultConfig, ...config, throwOnError: false, initialPageParam: args, });};
Nom de la méthode Meteor.
Arguments de la requête.
Clé unique pour la requête.
Configuration additionnelle.
Résultat de la requête via useInfiniteQuery.
useInfiniteQuery
Hook React Query pour exécuter une requête paginée avec Meteor.
Source