-
-
Notifications
You must be signed in to change notification settings - Fork 32
Closed
Labels
Description
First of all, I wanna say that I like hyper-fetch a lot!! Especially for the offline use-cases we're about to tackle, it seems the perfect solution.
Anyways, I found this inconsistency when creating a request. As by the documentation, you can append a response mapper. Here's an example:
export const getUsers = client
.createRequest<ObjectWithUsers>()({
method: "GET",
endpoint: "/users",
})
.setResponseMapper(async (response) => {
if (response.data) {
return {
...response,
data: {
...response.data,
users: response.data.map((user) => new User(user));
}
};
}
return response;
});
When using this request in a useFetch hook afterwards, I observe the following:
const { data, error, loading, onSuccess } = useFetch(getUsers);
- data: data contains the mapped response of getUsers (as expected).
- onSuccess: the request provided to your callback in onSuccess does not contain the mapped data.
Now I read that the responses are cached in their "original" form, but I would expect that since "data" and "onSuccess" are based on the same request definition (i.e. getUsers), they would both be provided with the same response.