For a given reducer, my redux state tree typically looks something like this:
{
someField: 'some value',
// ... more fields
metadata: {
pending: false,
fetched: true,
}
}
Typically, when I do an async request, I fire a SOME_ACTION_REQUEST
action, which sets the metadata.pending
property to true. It's reset to false again when the matching SOME_ACTION_RESPONSE
or SOME_ACTION_ERROR
event trickles in later.
However, the way I update the state is a bit verbose:
case actions.SOME_ACTION_REQUEST: {
return {
...state,
metadata: { ...state.metadata, pending: true },
};
}
Is there a simpler way of doing this?
Object.assign({}, state, { metadata: { pending: true } })
isn't very readable either.