import { Schema, useController } from '@rest-hooks/react'; import { __INTERNAL__ } from '@rest-hooks/react'; import { useCallback } from 'react'; import { FetchShape, ParamsFromShape, BodyFromShape, ReturnFromShape, } from '../endpoint/index.js'; const { createFetch } = __INTERNAL__; /** Build an imperative dispatcher to issue network requests. * @deprecated use https://resthooks.io/docs/api/Controller#fetch */ export default function useFetchDispatcher(throttle = false): < Shape extends FetchShape, any>, >( fetchShape: Shape & { update?: (...args: any) => Record any>; }, params: ParamsFromShape, body: BodyFromShape, ) => ReturnFromShape { const { dispatch } = useController(); const fetchDispatcher = useCallback( , any>>( fetchShape: Shape, params: ParamsFromShape, body: BodyFromShape, ) => { const action = createFetch(fetchShape, { params, body, throttle, }); dispatch(action); return action.meta.promise; }, [dispatch, throttle], ); // any is due to the ternary that we don't want to deal with in our implementation return fetchDispatcher as any; }