When to use transformResponse vs creating a selector #4611
-
I'm already using transformResponse to validate the response (I throw an error if it doesn't match some schema) . I have another use case where I need to mutate the response from the server. Specifically, there is a key value pair representing a date. The server returns it as an ISO 8601 datetime string, and it needs to be formatted into a more readable string. Is there a more "correct" place to do this mutation (between transformResponse vs doing it in a selector). Even an example for transformResponse transformResponse: (response, meta, arg) =>
response.some.deeply.nested.collection I could also envision as a selector. I like how in transformResponse, the mutation of the data is happening close to where the data is being fetched. Are there any rules of thumb, or anything I should take into consideration, for choosing between transforming data before it makes it into the cache (transformResponse) vs writing selectors to access and manipulate the cached data? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
you should use transformResponse when all you need is the transformed data, and you have no need for the original data. If you still need the original data (for example if you're transforming it multiple ways), then a selector is the correct approach. |
Beta Was this translation helpful? Give feedback.
you should use transformResponse when all you need is the transformed data, and you have no need for the original data.
If you still need the original data (for example if you're transforming it multiple ways), then a selector is the correct approach.