best practice for handling complex app state from multiple endpoints #4624
Unanswered
pseidemann
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
in the past I used redux only for app state but never rtk query. I had my own implementation for making api requests and called these functions from redux thunks, generating complex global app state from multiple different endpoints, basically merging data together or augmenting data of one endpoint A with the data from another B, while also needing the "verbatim" or preprocessed data from B alone.
I'm currently in the middle of migrating fully to rtk query.
now I'm wondering, what is the best practice for such use case?
creating an endpoint which does two queries is imo not the best option since at least one endpoint is also needed "standalone", and I don't want to replicate the endpoint implementation (maybe there is a fix for that? calling endpoints from the same api slice? possible?).
what I'm currently doing, is keeping my old redux thunks and calling my complex apis with
someEndpoint.initiate(undefined, { subscribe: false, forceRefetch: true })
but this probably defeats the purpose of rtk query?
where should I do the data merge? where the processing of the result of multiple endpoints?
should I keep using redux slices for this merged data or should I do everything in the api slice?
should I keep using thunks for this?
in the end, what I want to use in the react component, is some hook/selector which gives me the finished preprocessed/augmented/merged data from multiple endpoints with just one statement and not maybe using multiple query hooks and then merge data.
Beta Was this translation helpful? Give feedback.
All reactions