crudAction: (String) The CRUD operation being performed. One of "create", "read", "update", or "delete". This determines the CRUD Action types that are dispatched.
actionDefaults(Object): Properties that will be included on each dispatched action. The Request Action guide lists possible options, such as resourceType and resources. You must include resourceType.
Returns
(Object): An object with four methods: pending, succeeded, failed, and idle. These action creators return actions for you, based on the action properties that you provide to them.
Example
import createActionCreators from 'redux-resource-action-creators';
import store from './store';
const readActionCreators = createActionCreators('read', {
resourceType: 'books',
requestKey: 'getHomePageBooks',
list: 'homePageBooks',
mergeListIds: false
});
store.dispatch(readActionCreators.pending());
const req = fetchData((err, res, body) => {
if (req.aborted) {
store.dispatch(readActionCreators.idle());
} else if (err) {
store.dispatch(readActionCreators.failed());
} else {
store.dispatch(readActionCreators.succeeded({
resources: body
}));
}
});
To understand why you might use this library, compare that example versus this common Redux Resource code:
All that this library does is provides a simple pattern to write less, more expressive code. If you'd like, you could get many of the same benefits by defining shared action properties, and then spreading them in your actions: