swr-site
swr-site copied to clipboard
Feedback for “Conditional Fetching”
Hello! 👋
I am working with the conditional data fetching, and it seems like the following is true, even though I can't see it in the docs.
When sending a request with useSwr
, the result will be undefined, if the key function changes to return null after first sending the request. For example:
const { data, isValidating } = useSWR(
() => {
if (someCondition) {
return null;
}
return '/fetch/some/data';
},
fetcher
)
If someCondition
changes after the request is sent, data
will always be undefined, even if the initial request returns the data. Is this correct? It is what I am seeing in the app I am working on. Even though the request returns data, the data
return value from useSwr
is always undefined
because the fetcher
function changed to return null
.