5 ms·
Some good discussion on this over in the related Reddit thread: https://www.reddit.com/r/reactjs/comments/vhc30w/why_you_could_switch_from_redux_to_apollo_in_r
by acemarke 4y ago
Some good discussion on this over in the related Reddit thread:
https://www.reddit.com/r/reactjs/comments/vhc30w/why_you_could_switch_from_redux_to_apollo_in_react/ https://www.reddit.com/r/reactjs/comments/vhc30w/why_you_cou...
I'll paste in my comment from over there:
I have a few nitpicks with this post:
- It makes the usual conflation with "Apollo vs Redux" without really specifying that it's specifically focused on the "how much code do you have to write to manage data loading" use case
- While it does mention RTK and show usage of `createSlice` in the examples, the writing makes it sound like RTK is an afterthought. The examples are also hand-written thunks, without use of `createAsyncThunk`
- There's no mention of RTK Query whatsoever. Not only does RTK Query solve the exact same use case as Apollo (abstracting data fetching and loading state, with hooks that do that work for you), but we specifically have examples showing using RTK Query to fetch GraphQL data [0] and an entire GraphQL codegen for RTK Query [1].
At that point, choosing between Apollo and RTK Query becomes a discussion about tradeoffs and differences in API design, feature sets, and intent, such as "Apollo has a normalized cache, RTK Query has a document/response cache" [2] and deciding which one is a better fit, rather than "Apollo replaces Redux".
[0] https://redux-toolkit.js.org/rtk-query/usage/examples#react-with-graphql https://redux-toolkit.js.org/rtk-query/usage/examples#react-...
[1] https://www.graphql-code-generator.com/plugins/typescript-rtk-query https://www.graphql-code-generator.com/plugins/typescript-rt...
[2] https://redux-toolkit.js.org/rtk-query/usage/cache-behavior#no-normalized-or-de-duplicated-cache https://redux-toolkit.js.org/rtk-query/usage/cache-behavior#...