Transform Response

Last updated 6 months ago
  • You can configure transformResponse for a specific action:

For instance if you want to sort by your response before it hits the store

import {sortBy} from 'lodash';
‚Äč
export const {types, actions, reducers} = createResource({
name: 'user',
url: 'https://foo.com/users/:id',
actions: {
fetch: {
transformResponse: res => ({res, body: sortBy(res.body, 'date')})
},
update: {
headers: {
'X-Custom-Header': 'foobar'
}
}
}
});