UNPKG

@mussnad/frappe-react-query

Version:
120 lines (119 loc) 4.8 kB
import { QueryKey } from '@tanstack/react-query'; import { FrappeError } from '../types'; import { ApiParams, TypedResponse } from '@mussnad/frappe-js-client/dist/call/types'; /** * Hook to make a GET request to the server * * @param method - name of the method to call (will be dotted path e.g. "frappe.client.get_list") * @param params - parameters to pass to the method * @param queryKey - optional QueryKey that will be used to cache the result. If not provided, the method name with the URL params will be used as the key * @param options [Optional] React Query configuration options for fetching data * @param type - type of the request to make - defaults to GET * * @typeParam T - Type of the data returned by the method * * @returns an object with data, error, isLoading, and other React Query properties * * @example * * const { data, error, isLoading } = useFrappeGetCall('frappe.client.get_list', { * filters: [{ field: 'name', operator: 'like', value: 'test' }], * fields: ['name', 'title'], * }) */ export declare const useFrappeGetCall: <T extends TypedResponse<any>>(method: string, params?: ApiParams, queryKey?: QueryKey, options?: any, type?: "GET" | "POST") => import('@tanstack/react-query').DefinedUseQueryResult<T, Error>; /** * Hook to prefetch data * * @param method - name of the method to call (will be dotted path e.g. "frappe.client.get_list") * @param params - parameters to pass to the method * @param queryKey - optional QueryKey that will be used to cache the result. If not provided, the method name with the URL params will be used as the key * @param type - type of the request to make - defaults to GET * * @typeParam T - Type of the data returned by the method * * @returns an object with data, error, isLoading, and other React Query properties * * @example * * const prefetch = useFrappePrefetchCall('frappe.client.get_list', { * filters: [{ field: 'name', operator: 'like', value: 'test' }], * fields: ['name', 'title'], * }) */ export declare const useFrappePrefetchCall: <T extends TypedResponse<any>>(method: string, params?: ApiParams, queryKey?: QueryKey, type?: "GET" | "POST") => () => void; /** * Hook for POST requests * * @param method - name of the method to call (will be dotted path e.g. "frappe.client.get_list") * @param params - parameters to pass to the method * * @typeParam T - Type of the data returned by the method * * @returns an object with data, error, isLoading, and other React Query properties * * @example * * const { data, error, isLoading } = useFrappePostCall('frappe.client.get_list', { * filters: [{ field: 'name', operator: 'like', value: 'test' }], * fields: ['name', 'title'], * }) */ export declare const useFrappePostCall: <T extends TypedResponse<any>>(method: string) => { call: import('@tanstack/react-query').UseMutateFunction<T, FrappeError, ApiParams, unknown>; result: T | undefined; loading: boolean; error: FrappeError | null; isCompleted: boolean; reset: () => void; }; /** * Hook for PUT requests * * @param method - name of the method to call (will be dotted path e.g. "frappe.client.get_list") * @param params - parameters to pass to the method * * @typeParam T - Type of the data returned by the method * * @returns an object with data, error, isLoading, and other React Query properties * * @example * * const { data, error, isLoading } = useFrappePutCall('frappe.client.get_list', { * filters: [{ field: 'name', operator: 'like', value: 'test' }], * fields: ['name', 'title'], * }) */ export declare const useFrappePutCall: <T extends TypedResponse<any>>(method: string) => { call: import('@tanstack/react-query').UseMutateFunction<T, FrappeError, ApiParams, unknown>; result: T | undefined; loading: boolean; error: FrappeError | null; isCompleted: boolean; reset: () => void; }; /** * Hook for DELETE requests * * @param method - name of the method to call (will be dotted path e.g. "frappe.client.get_list") * @param params - parameters to pass to the method * * @typeParam T - Type of the data returned by the method * * @returns an object with data, error, isLoading, and other React Query properties * * @example * * const { data, error, isLoading } = useFrappeDeleteCall('frappe.client.get_list', { * filters: [{ field: 'name', operator: 'like', value: 'test' }], * fields: ['name', 'title'], * }) */ export declare const useFrappeDeleteCall: <T extends TypedResponse<any>>(method: string) => { call: import('@tanstack/react-query').UseMutateFunction<T, FrappeError, ApiParams, unknown>; result: T | undefined; loading: boolean; error: FrappeError | null; isCompleted: boolean; reset: () => void; };