import { Identifier, Record } from '../types'; import { MutationOptions, Mutation } from './useMutation'; /** * Get a callback to call the dataProvider.updateMany() method, the result * of the call (the list of updated record ids), and the loading state. * * The return value updates according to the request state: * * - initial: [updateMany, { loading: false, loaded: false }] * - start: [updateMany, { loading: true, loaded: false }] * - success: [updateMany, { data: [data from response], loading: false, loaded: true }] * - error: [updateMany, { error: [error from response], loading: false, loaded: false }] * * @param resource The resource name, e.g. 'posts' * @param ids The resource identifiers, e.g. [123, 456] * @param data The updates to merge into all records, e.g. { views: 10 } * @param options Options object to pass to the dataProvider. May include side effects to be executed upon success or failure, e.g. { onSuccess: { refresh: true } } * * @returns The current request state. Destructure as [updateMany, { data, error, loading, loaded }]. * * The updateMany() function can be called in 3 different ways: * - with the same parameters as the useUpdateMany() hook: update(resource, ids, data, options) * - with the same syntax as useMutation: update({ resource, payload: { ids, data } }, options) * - with no parameter (if they were already passed to useUpdateMany()): updateMany() * * @example // set params when calling the updateMany callback * * import { useUpdateMany } from '../app'; * * const BulkResetViewsButton = ({ selectedIds }) => { * const [updateMany, { loading, error }] = useUpdateMany(); * const handleClick = () => { * updateMany('posts', selectedIds, { views: 0 }); * } * if (error) { return

ERROR

; } * return ; * }; * * @example // set params when calling the hook * * import { useUpdateMany } from '../app'; * * const BulkResetViewsButton = ({ selectedIds }) => { * const [updateMany, { loading, error }] = useUpdateMany('posts', selectedIds, { views: 0 }); * if (error) { return

ERROR

; } * return ; * }; */ declare const useUpdateMany: (resource?: string, ids?: Identifier[], data?: Partial, options?: MutationOptions) => UseUpdateManyHookValue; declare type UseUpdateManyHookValue = [ (resource?: string | Partial | Event, ids?: Identifier[] | Partial, data?: Partial, options?: MutationOptions) => void | Promise, { data?: Identifier[]; total?: number; error?: any; loading: boolean; loaded: boolean; } ]; export default useUpdateMany;