import type { Schema, NetworkError, EndpointInterface, UnknownError, FetchFunction, } from '@rest-hooks/react'; import { useError as useErrorNew } from '@rest-hooks/react'; import { useMemo } from 'react'; import shapeToEndpoint from '../endpoint/adapter.js'; import { ReadShape, ParamsFromShape } from '../endpoint/index.js'; export type ErrorTypes = NetworkError | UnknownError; type UseErrorReturn

= P extends [null] ? undefined : ErrorTypes | undefined; /** * Get any errors for a given request * @see https://resthooks.io/docs/api/useError */ export default function useError< E extends | Pick< EndpointInterface, 'key' | 'schema' | 'invalidIfStale' > | Pick, 'getFetchKey' | 'schema' | 'options'>, Args extends | (E extends { key: any } ? readonly [...Parameters] : readonly [ParamsFromShape]) | readonly [null], >(endpoint: E, ...args: Args): UseErrorReturn { const adaptedEndpoint: any = useMemo(() => { return shapeToEndpoint(endpoint); // we currently don't support shape changes // eslint-disable-next-line react-hooks/exhaustive-deps }, []); return useErrorNew(adaptedEndpoint, ...args); }