diff --git a/packages/rest-hooks/src/react-integration/hooks/useFetcher.ts b/packages/rest-hooks/src/react-integration/hooks/useFetcher.ts index 9b2ccada9f08..f9ffdd22286a 100644 --- a/packages/rest-hooks/src/react-integration/hooks/useFetcher.ts +++ b/packages/rest-hooks/src/react-integration/hooks/useFetcher.ts @@ -1,4 +1,3 @@ -import { useContext, useRef, useCallback } from 'react'; import { FetchAction, UpdateFunction, ReceiveTypes } from 'rest-hooks/types'; import { RECEIVE_DELETE_TYPE, @@ -17,6 +16,8 @@ import { } from 'rest-hooks/resource'; import { DispatchContext } from 'rest-hooks/react-integration/context'; +import { useContext, useRef, useCallback } from 'react'; + const SHAPE_TYPE_TO_RESPONSE_TYPE: Record< FetchShape['type'], ReceiveTypes @@ -46,7 +47,10 @@ export default function useFetcher< fetchShape: Shape, throttle = false, ): Shape extends DeleteShape - ? (params: ParamsFromShape, body: BodyFromShape) => Promise + ? ( + params: ParamsFromShape, + body: BodyFromShape, + ) => ReturnType : < UpdateParams extends OptimisticUpdateParams< SchemaFromShape, @@ -56,7 +60,7 @@ export default function useFetcher< params: ParamsFromShape, body: BodyFromShape, updateParams?: UpdateParams | undefined, - ) => Promise { + ) => ReturnType { const dispatch = useContext(DispatchContext); // we just want the current values when we dispatch, so diff --git a/packages/rest-hooks/src/react-integration/hooks/useResource.ts b/packages/rest-hooks/src/react-integration/hooks/useResource.ts index 82a154ef15c5..177813b192ea 100644 --- a/packages/rest-hooks/src/react-integration/hooks/useResource.ts +++ b/packages/rest-hooks/src/react-integration/hooks/useResource.ts @@ -1,4 +1,3 @@ -import { useMemo, useContext } from 'react'; import { ReadShape, Denormalize, @@ -8,6 +7,8 @@ import { import { useDenormalized } from 'rest-hooks/state/selectors'; import { StateContext } from 'rest-hooks/react-integration/context'; +import { useMemo, useContext } from 'react'; + import useRetrieve from './useRetrieve'; import useError from './useError'; import hasUsableData from './hasUsableData'; @@ -61,7 +62,7 @@ function useManyResources[]>( // only wait on promises without results .map( (p, i) => - !hasUsableData(denormalizedValues[i][1], resourceList[i][0]) && p, + !hasUsableData(denormalizedValues[i][1], resourceList[i][0]) && !!p, ); // throw first valid error diff --git a/packages/rest-hooks/src/react-integration/hooks/useRetrieve.ts b/packages/rest-hooks/src/react-integration/hooks/useRetrieve.ts index 6710687ce7b4..aad8db456e52 100644 --- a/packages/rest-hooks/src/react-integration/hooks/useRetrieve.ts +++ b/packages/rest-hooks/src/react-integration/hooks/useRetrieve.ts @@ -1,4 +1,4 @@ -import { ReadShape, Schema } from 'rest-hooks/resource'; +import { ReadShape, ParamsFromShape } from 'rest-hooks/resource'; import { useMemo } from 'react'; @@ -6,10 +6,10 @@ import useFetcher from './useFetcher'; import useExpiresAt from './useExpiresAt'; /** Request a resource if it is not in cache. */ -export default function useRetrieve< - Params extends Readonly, - S extends Schema ->(fetchShape: ReadShape, params: Params | null) { +export default function useRetrieve>( + fetchShape: Shape, + params: ParamsFromShape | null, +) { const fetch = useFetcher(fetchShape, true); const expiresAt = useExpiresAt(fetchShape, params);