DEV Community

Discussion on: React State Management in 2020

Collapse
 
juliang profile image
Julian Garamendy • Edited

Hi! Thank you for taking the time to read and comment.

I do agree with the cache usage argument although for some applications I think storage of data retrieved is needed if you need to transform it in some way.

We're not constrained to cache the data as it arrives from the server. Both SWR and React Query take any async function (i.e. a function returning a Promise) as argument. This means you can write a function that calls fetch or axios awaits the call, then transforms the data and returns it.

This way cache will contain the transformed data instead; and we don't need to involve a state-management library only for that.

Collapse
 
wicked7000 profile image
Wicked

Ah I see that's quite a clean way of dealing with it I might have to look more into that. Is the idea to always use a cache retreval rather than holding in directly in state? Or do think there is a use case for holding it in state? (In your opinion)