import { Identifier, Record } from '../types'; import { Refetch } from './useQueryWithStore'; declare type Callback = (args?: any) => void; interface UseGetManyOptions { onSuccess?: Callback; onFailure?: Callback; enabled?: boolean; } interface UseGetManyResult { data: Record[]; error?: any; loading: boolean; loaded: boolean; refetch: Refetch; } /** * Call the dataProvider.getMany() method and return the resolved result * as well as the loading state. * * The return value updates according to the request state: * * - start: { loading: true, loaded: false, refetch } * - success: { data: [data from response], loading: false, loaded: true, refetch } * - error: { error: [error from response], loading: false, loaded: false, refetch } * * This hook will return the cached result when called a second time * with the same parameters, until the response arrives. * * This hook aggregates and deduplicates calls to the same resource, so for instance, if an app calls: * * useGetMany('tags', [1, 2, 3]); * useGetMany('tags', [3, 4]); * * during the same tick, the hook will only call the dataProvider once with the following parameters: * * dataProvider(GET_MANY, 'tags', [1, 2, 3, 4]) * * @param resource The resource name, e.g. 'posts' * @param ids The resource identifiers, e.g. [123, 456, 789] * @param {Object} options Options object to pass to the dataProvider. * @param {boolean} options.enabled Flag to conditionally run the query. If it's false, the query will not run * @param {Function} options.onSuccess Side effect function to be executed upon success, e.g. { onSuccess: { refresh: true } } * @param {Function} options.onFailure Side effect function to be executed upon failure, e.g. { onFailure: error => notify(error.message) } * * @returns The current request state. Destructure as { data, error, loading, loaded, refetch }. * * @example * * import { useGetMany } from '../app'; * * const PostTags = ({ record }) => { * const { data, loading, error } = useGetMany('tags', record.tagIds); * if (loading) { return ; } * if (error) { return

ERROR

; } * return ( * * ); * }; */ declare const useGetMany: (resource: string, ids: Identifier[], options?: UseGetManyOptions) => UseGetManyResult; export default useGetMany;