DEV Community

Discussion on: Why I Stopped Using Redux

Collapse
 
ryanmr profile image
Ryan Rampersad

I use redux to compose multiple API calls into something that my frontends can display and for refresh-safe persistence with redux-persist. Can react-query help with data composition and that persistence?

Collapse
 
g_abud profile image
Gabriel Abud • Edited

I assume by data composition you mean creating your own, normalized store on the frontend?

This is kind of fundamentally different from how react-query and SWR work. I think these libraries discourage you from creating this normalized state yourself. Think of each API call as unique key in your global cache. You could certainly manage these yourself but then I think you lose the benefits that these libraries provide and at that point you may as well be using Redux. The normalization aspects should fall on the backend developers, and we shouldn't be totally against denormalization everywhere on the frontend anyway. Sometimes it makes more sense to send back denormalized data from the backend to avoid making N+1 queries.

As for persistence, why is that important to you? To avoid network latency? I think react-query and SWR prioritize data consistency over reducing network calls, so in general it will be easier to manage consistency. You could still store it in local storage though, it's just not provided by default. Take a look at this discussion for more if persisting is important to you: github.com/tannerlinsley/react-que...

It's possible that your application might have a very good use case for Redux, but I would encourage you to check out these other libraries especially if you find managing your Redux store to have gotten overly-complex.