redux-load-error
Pre-reducer for UI reducers that can be loading or have an error
Installation
$ npm install --save redux-load-error
Usage
Compose your reducer with this pre-reducer to have it handle the loading
and error
properties for the UI component you are referencing.
You need to declare which actions will cause the component to load, display an error, or display its default content.
;; const loadingActions = actionsLOADING;const notLoadingActions = actionsDONE;const errorActions = actionsERROR; const reducer = { } reducer loadingActions notLoadingActions errorActions;
Now the pre-reducer will handle the loading
and error
properties for you.
;;; let store = ; store; // loading: true, error: undefined store;// loading: false, error: undefined store;// loading: false, error: 'An error'
Reference
loadAndError(reducer, loadingActions, notLoadingActions, errorActions, [options])
reducer
The base reducer to compose
loadingActions
An array of action types that will set loading
to true
and error
to undefined
notLoadingActions
An array of action types that will set loading
to false
and error
to undefined
errorActions
An array of action types that will set loading
to false
and error
to action.error
options
An object containing one, all or none of the following options:
loadingProp
A string that denotes the property key to use for loading
, defaults to loading
errorProp
A string that denotes the property key to use for error
, defaults to error
keepErrors
If set to true
nothing will set the error
property to undefined
, you can do it in your base reducer. Defaults to false
.
Related
- react-hoc-loading: HOC to show and hide a loading image or message across all your mayor UI components
- react-bootstrap-hoc-error: HOC to show and hide errors across all your mayor UI components using react-bootstrap
License
MIT © Marco Scabbiolo