-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
RTKQ: refetch() can't be a promise ? #1939
Comments
The lazyQuery trigger can be awaited in 1.7. |
Just adding a concrete use case here: we use either |
@jpcody but you already have a |
Yes. which mostly fits my needs, but not always. // Component A - listing all dogs
const { data, isFetching, isLoading, refetch } = useGetDogsQuery()
<PullToRefresh onRefresh={refetch} refreshing={isFetching && !isLodading} />
// Component B - showing a single dog
const fetchDog, { isFetching, isLoading } = useLazyGetDogByIdQuery()
const refetch = useCallback(() => fetchDog(id), [id])
<PullToRefresh onRefresh={refetch} refreshing={isFetching && !isLodading} /> Component A actually behaves as expected, but component B doesn't, which leads me to want an async refetch. In component B, the lazy query only returns That lazy query behavior is unexpected to me, and perhaps I'm doing something wrong on my end. But given that behavior, in my pull-to-refresh component, I'd like to simply |
Yes, https://redux-toolkit.js.org/rtk-query/usage/queries#frequently-used-query-hook-return-values |
Sorry, this is difficult to communicate about. What's unexpected to me is that when a component is re-mounted, and thus the query is re-issued with a different argument and different data is fetched, |
@awdyson if nothing else, a respectful tone would be nice. As already stated, there is no philosophical reason against doing this (it was just added in other places in later versions of RTK, but not there yet) - and thus also no reason for someone not to just whip up a PR if they need this feature. It's not a lot of code, in fact I've just done it - #2212. Please go ahead and test the CodeSandbox build. I'm getting breakfast now. |
@phryneas I'm really sorry, and I'm grateful for the work being done here. In good faith, I tried my code against that PR's commit hash. I've got the branch pulled locally to see if I can figure out where to change that, but I often feel a little out-classed by open source libraries. |
Merged #2212 into the v1.9 branch - should be available there via the PR preview build. |
Could you help me to get why RTKQ useQuery's refetch is not a promise-like thing ? (what is motivation)
I mean - I can't await it e.t.c
same for lazyQuery and it's trigger
The text was updated successfully, but these errors were encountered: