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.
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)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hi! Thank you for taking the time to read and comment.
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
oraxios
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.
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)