import { useCallback } from 'react' ; import { Identifier , Record } from '../types' ; import useMutation , { MutationOptions , Mutation } from './useMutation' ; param resource param id param data param previousData param options returns example example example const useUpdate = < RecordType extends Record = Record > ( resource ? , id ? , data ? , previousData ? , options ? ) : UseUpdateHookValue < RecordType > => { const [ mutate , state ] = useMutation ( { type : 'update' , resource , payload : { id , data , previousData } } , options ) ; const update = useCallback ( ( resource ? , id ? , data ? , previousData ? , options ? ) => { if ( typeof resource === 'string' ) { const query = { type : 'update' , resource , payload : { id : id as Identifier , data , previousData , } , } ; return mutate ( query , options ) ; } else { return mutate ( resource as Mutation | Event , id as MutationOptions ) ; } } , [ mutate ] ) ; return [ update , state ] ; } ; type UseUpdateHookValue < RecordType extends Record = Record > = [ ( resource ? : string | Partial < Mutation > | Event , id ? : Identifier | Partial < MutationOptions > , data ? : Partial < RecordType > , previousData ? : any , options ? : MutationOptions ) => void | Promise < any > , { data ? : RecordType ; total ? : number ; error ? : any ; loading : boolean ; loaded : boolean ; } ] ; export default useUpdate ;