useUnmountSignal() — A React Hook to cancel promises when a component is unmounted

A React Hook that wraps around the almighty AbortController. It will automatically call abort() on the created AbortSignal instance when the component unmounts. import useUnmountSignal from ‘use-unmount-signal’; function Example() { const unmountSignal = useUnmountSignal(); return ( <button onClick={() => fetch(‘https://ping.example.com’, { signal: unmountSignal }) }> Ping </button> ); } Installation per NPM: npm i use-unmount-signal …


This content originally appeared on Bram.us and was authored by Bramus!

A React Hook that wraps around the almighty AbortController. It will automatically call abort() on the created AbortSignal instance when the component unmounts.

import useUnmountSignal from 'use-unmount-signal';

function Example() {
  const unmountSignal = useUnmountSignal();
  return (
    <button
      onClick={() =>
        fetch('https://ping.example.com', { signal: unmountSignal })
      }>
      Ping
    </button>
  );
}

Installation per NPM:

npm i use-unmount-signal

use-unmount-signal (GitHub) →


This content originally appeared on Bram.us and was authored by Bramus!


Print Share Comment Cite Upload Translate Updates
APA

Bramus! | Sciencx (2021-07-27T23:09:38+00:00) useUnmountSignal() — A React Hook to cancel promises when a component is unmounted. Retrieved from https://www.scien.cx/2021/07/27/useunmountsignal-a-react-hook-to-cancel-promises-when-a-component-is-unmounted/

MLA
" » useUnmountSignal() — A React Hook to cancel promises when a component is unmounted." Bramus! | Sciencx - Tuesday July 27, 2021, https://www.scien.cx/2021/07/27/useunmountsignal-a-react-hook-to-cancel-promises-when-a-component-is-unmounted/
HARVARD
Bramus! | Sciencx Tuesday July 27, 2021 » useUnmountSignal() — A React Hook to cancel promises when a component is unmounted., viewed ,<https://www.scien.cx/2021/07/27/useunmountsignal-a-react-hook-to-cancel-promises-when-a-component-is-unmounted/>
VANCOUVER
Bramus! | Sciencx - » useUnmountSignal() — A React Hook to cancel promises when a component is unmounted. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/07/27/useunmountsignal-a-react-hook-to-cancel-promises-when-a-component-is-unmounted/
CHICAGO
" » useUnmountSignal() — A React Hook to cancel promises when a component is unmounted." Bramus! | Sciencx - Accessed . https://www.scien.cx/2021/07/27/useunmountsignal-a-react-hook-to-cancel-promises-when-a-component-is-unmounted/
IEEE
" » useUnmountSignal() — A React Hook to cancel promises when a component is unmounted." Bramus! | Sciencx [Online]. Available: https://www.scien.cx/2021/07/27/useunmountsignal-a-react-hook-to-cancel-promises-when-a-component-is-unmounted/. [Accessed: ]
rf:citation
» useUnmountSignal() — A React Hook to cancel promises when a component is unmounted | Bramus! | Sciencx | https://www.scien.cx/2021/07/27/useunmountsignal-a-react-hook-to-cancel-promises-when-a-component-is-unmounted/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.