Action observer
HOC which allows you to observe the status of an asynchronous actions.
Features
- can rerender component when status has changed
- can abort axios requests on component unmount
- can abort axios request on second call
Installation
yarn add react-action-observer
Usage
const fetchGeolocation = @actionObserver static propTypes = observeAction: PropTypesfuncisRequired getObservedAction: PropTypesfuncisRequired async { const observeAction = thisprops const data = await ... } { const getObservedAction = thisprops const action = return <div> <button onClick=thishandleClick> Fetch </button> action && <div>Loading ...</div> action && <pre> JSON </pre> </div> }
Props
- observeAction(getAction, { key = '', shouldComponentUpdate = true, silent = true } = {})
- getObservedAction(key = '')