@freckle/cancelable-promise
v1.0.0
Published
Cancelable promise utilities
Downloads
2,609
Keywords
Readme
@freckle/cancelabe-promise
Utilities to create a promise that can be canceled.
Install
yarn add @freckle/cancelable-promise
Versioning and release process
See RELEASE.md.
Usage
const expensiveOperation = () => fetchData().then(parse).then(transform)
const Component = () => {
const [result, setResult] = setState(null)
useEffect(() => {
const promise = makeCancelable(expensiveOperation).then(res => {
setResult(res)
})
return () => {
// Cancel on cleanup
promise.cancel()
}
})
return result
}