Package Exports
- @sevenoutman/use-abandon-on-unmount
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@sevenoutman/use-abandon-on-unmount) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
useAbandonOnUnmount
React Hook for abandoning promises upon component unmounting
yarn add @sevenoutman/use-abandon-on-unmount
Usage
import useAbandonOnUnmount from '@sevenoutman/use-abandon-on-unmount';
function App() {
const [data, setData] = useState();
const abandonOnUnmount = useAbandonOnUnmount();
const fetchData = useCallback(async () => {
const result = await abandonOnUnmount(requestData());
setData(result); // Will not excute after this component unmounts
}, [setData]);
return (
// ...
);
}
Why?
Get you rid of this:
Warning: Can only update a mounted or mounting component. This usually means you called setState, replaceState, or forceUpdate on an unmounted component. This is a no-op.