-
-
Notifications
You must be signed in to change notification settings - Fork 603
Open
Labels
enhancementNew feature or requestNew feature or requestswr-openapiRelevant to swr-openapi libraryRelevant to swr-openapi library
Description
Description
Sometimes, the pagination info is given in resoponse headers such as wordpress rest api.
Proposal
We can customize the fetcher function to access response headers directly:
const { data, error, isLoading, isValidating, mutate } = useQuery(
path,
init,
{
fetcher: async (path, init) => {
const res = await wpClient.GET(path, init);
if (res.error) {
throw res.error;
}
// Access response headers here
const totalCount = res.response.headers.get('x-wp-total');
return res.data;
},
},
);Alternatively, we could enhance the hook to return response headers directly:
const { data, headers, error, isLoading, isValidating, mutate } = useQuery(
path,
init,
config,
);The useInfinite hook should also support response header access for consistency.
Extra
- I’m willing to open a PR (see CONTRIBUTING.md)
BPreisner and marigohtj
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestswr-openapiRelevant to swr-openapi libraryRelevant to swr-openapi library