@sevenoutman/use-abandon-on-unmount
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

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.

Package Sidebar

Install

npm i @sevenoutman/use-abandon-on-unmount

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

3.26 kB

Total Files

6

Last publish

Collaborators

  • sevenoutman