-
-
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
useQueries
hook
#2402
base: master
Are you sure you want to change the base?
useQueries
hook
#2402
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 4e707bf:
|
With the implementation I just pushed, it is now possible to do const [lastPage, currentPage, nextPage] = api.endpoints.getPage.useQueries({page: 1}, {page: 2}, {page: 3}) So that's a bit of a win. But this now shows a fundamental design flaw: An array-based We would essentially be in need of "component keys" (to compare this to React) to figure out "which array member changed, which was inserted, which was deleted" etc. There are two ways I see out of that:
const { lastPage, currentPage, nextPage } = useQueries({ lastPage: {page: 1}, currentPage: {page:2}, nextPage: {page: 3} }) While this is more code, it might also be more readable in the end. So, yeah... open to any comments you might have on this. Actually, @TkDodo - I'd love your opinion on this. As far as I understand you also added a |
We have query keys, so we know which observer to reuse in the next render. Lagged queries were difficult to get right though if the key changes. I think we still rely on index as a fallback. It's not perfect. I think if you change keys and change the length / order of the array at the same time and use lagged queries with keepPreviousData, it might not work. It's a pretty edgy case though |
Incremental means that we show data as soon as they're discovered We're using react-query, because useQueries is missing in rtk-query: reduxjs/redux-toolkit#2402
Incremental means that we show data as soon as they're discovered We're using react-query, because useQueries is missing in rtk-query: reduxjs/redux-toolkit#2402
Any updates on this? I really need something like that on a project I am working on |
@NunoCardoso nope, none (as evidenced by the fact that the PR has sat here for two years untouched). I'm hoping to spend some time working on RTKQ features in the next few months, but no ETA or guarantees on which features will end up getting worked on first. |
Of course. I will use this snippet from kellengreen for now, I think it does the trick while this is still on backlog. |
This is a WIP towards building a
useQueries
hook , per #2398 .So far I have a slightly wonky prototype
useQuerySubscriptions
hook. It doesn't break any existing tests which I find kinda unsettling.