-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The isValidating
flag is no longer changing?
#224
Comments
Just tested replacing Is there a way I can write this export default function useRequest(request, { initialData, ...config } = {}) {
const { data: response, isValidating, error, revalidate } = useSWR(
request && JSON.stringify(request),
() => axios(request),
{
...config,
initialData: initialData && {
status: 200,
statusText: 'InitialData',
headers: {},
data: initialData,
},
}
);
return {
isValidating,
error,
revalidate,
data: response && response.data,
response,
};
} |
This looks like it's because You can keep the getters by mutating the returned object to add your own properties: export default function useRequest(request, { initialData, ...config } = {}) {
const returned = useSWR(
request && JSON.stringify(request),
() => axios(request),
{
...config,
initialData: initialData && {
status: 200,
statusText: 'InitialData',
headers: {},
data: initialData,
},
}
);
returned.response = returned.data
return returned
} I'm not entirely sure if there's issues with this approach though. It is rather unexpected though - I had the same issue but I was spreading the entire response of |
@davecoates Yeah, your workaround seem to work for me too, but not sure if the result of it is different from what I had already. And no idea if either of our solutions break/keep the optimization they've implemented with these getters. 🤔 |
Yeah sorry for your case you'd want to add a getter on eg. instead of Object.defineProperties(returned, {
response: {
get() {
return this.data;
}
},
}); |
Not sure that would work since I also replace What I'm trying to do here is that |
Bumping this issue. While following the steps in the readme and not wrapping the SWR request I am seeing Using version 0.1.16, downgrading to 0.1.15 fixes the issue. |
When using the spread operator, const { data, ...returned } = useSWR(...)
console.log(returned.isValidating) // will be undefined Currently, we don't have a easy fix for it. I'll suggest not using const swr = useSWR(...)
const { data } = swr
console.log(swr.isValidating) // will change over time |
The getter improvement reduces unnecessary re-renders dramatically. I'll keep this issue open and look for a better solution, or add a notice on the documentation. |
Can we add |
From version
0.1.16
theisValidating
flag doesn't seem to change anymore, it just stays at false, even when there is a request going on. Has the "API" of it changed after #186? Do I need to read it differently or something? Is it because I have wrappeduseSWR
in my own hook?Is there something in the way I get and pass on the returned values from
useSWR
here which is causing theisValidating
flag not to change? If so, how would you suggest I do it instead?Adding the following where I use my hook, just results in a single log message of
undefined
.The text was updated successfully, but these errors were encountered: