Skip to content
This repository has been archived by the owner on Nov 11, 2023. It is now read-only.

Commit

Permalink
Allow fetchData in useGet to return data (so refetch can return data)
Browse files Browse the repository at this point in the history
  • Loading branch information
amacleay-cohere authored and fabien0102 committed Oct 7, 2021
1 parent cf9912c commit 925f2a2
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/useGet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export interface UseGetReturn<TData, TError, TQueryParams = {}, TPathParams = un
/**
* Refetch
*/
refetch: (options?: RefetchOptions<TData, TError, TQueryParams, TPathParams>) => Promise<void>;
refetch: (options?: RefetchOptions<TData, TError, TQueryParams, TPathParams>) => Promise<TData | null>;
}

export function useGet<TData = any, TError = any, TQueryParams = { [key: string]: any }, TPathParams = unknown>(
Expand Down Expand Up @@ -211,6 +211,7 @@ export function useGet<TData = any, TError = any, TQueryParams = { [key: string]
data: resolvedData,
response: originalResponse,
}));
return resolvedData;
} catch (e) {
// avoid state updates when component has been unmounted
// and when fetch/processResponse threw an error
Expand All @@ -233,6 +234,8 @@ export function useGet<TData = any, TError = any, TQueryParams = { [key: string]
if (!props.localErrorOnly && context.onError) {
context.onError(error, () => _fetchData(props, context, abort, getAbortSignal));
}

return;
}
},
[
Expand Down

6 comments on commit 925f2a2

@LevKanter
Copy link

@LevKanter LevKanter commented on 925f2a2 Dec 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @amacleay-cohere @fabien0102 , just curious if you're planning to publish this change soon on NPM? It's really handy for something I'm working on using restful-react. ;)

@fabien0102
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I will publish a new version today :) Sorry for the delay, this is sometime hard to keep everything in track ^^ Thanks for the reminder! 😁

@fabien0102
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LevKanter Sorry, since I’m not part of contiamo anymore, I’m lacking of permission on this project, this will be published with #378 release 😉

@micha-f
Copy link
Member

@micha-f micha-f commented on 925f2a2 Dec 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fabien0102 Thank you for the ping. I merged #378 . Anything else that needs to be done to release?

@fabien0102
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Should be good! Bumping the version number in package.json did trigger a new release 😃

@LevKanter
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Please sign in to comment.