| * Service fetcher does fetching and updating store * Component does subscribing * React does updating component tree with changes. If a component wants changes it must subscribe. If not, it doesn't. If there is a change, subscribed components get updates. If not, they don't. Responses are (conditionally) cached in the store by its respective service. Any component that wants data just asks the service. Service fetches from the store or remote. I can customize and unit test the the service. I don't see the overlap in responsibility between any state lib (react or whatever in this case) and the purpose built service. What is react query's role here ? |
The set of possible events any given query might need to subscribe to is massive. Yes, you can build a large app with a pub/sub model but the number of subscriptions runs away from you and it gets really hard to know which of 1000 subscriptions you need to refresh when an association between two random pieces of data is created/deleted.
Associations are where you really get screwed IMO.
That said, despite exploring lots of possibilities I don’t think there’s any perfect way to do this automatically. So while I think you’re hand-waving away a hard problem, I also think your proposed solution is probably one of the better ones.
Still, I don’t think you should pooh-pooh people trying to solve the general problem. It’s a worthy one.