upsertResources(resources, newResources, [mergeResources])
Add new or update existing resources in your state tree.
Arguments
resources
(Object): The current resources object from your state tree.newResources
(Array|Object): The new resources to add or update.[
mergeResources
] (Boolean): Whether or not to merge individual resources with the existing resource in the store, or to replace it with the new data. Defaults totrue
.
Returns
(Object
): The updated resources object.
Example
import { upsertResources } from 'redux-resource';
import actionTypes from './my-action-types';
export default function reducer(state, action) {
switch (action.type) {
case (actionTypes.CREATE_RESOURCES_CUSTOM): {
const newResources = upsertResources({
resources: state.resources,
newResources: action.resources
});
return {
...state,
resources: newResources
};
}
}
}
Tips
- This is used internally within the reducer returned by
resourceReducer
to add and update resources in the store. You will typically only need to use this function if you're authoring a plugin.