Utilities to create a promise that can be canceled.
yarn add @freckle/cancelable-promise
See RELEASE.md.
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
}