{"_id":"use-unmount-signal","_rev":"52-9f812e4958ea57507a983dd94b5cc5ec","name":"use-unmount-signal","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"use-unmount-signal","version":"1.0.0","keywords":["react","hook","unmount","cancel","abortcontroller","abortsignal"],"author":{"name":"Expo"},"license":"MIT","_id":"use-unmount-signal@1.0.0","maintainers":[{"name":"ide","email":"ide+npm@jameside.com"}],"homepage":"https://github.com/expo/use-unmount-signal#readme","bugs":{"url":"https://github.com/expo/use-unmount-signal/issues"},"dist":{"shasum":"f6e3edc8ea7870a1bb7d79e750743e1a5735080e","tarball":"https://registry.npmjs.org/use-unmount-signal/-/use-unmount-signal-1.0.0.tgz","fileCount":13,"integrity":"sha512-ig9nY8X/jH8/zoZ4ZemiqZd1BxZdIWEX0LafYhkZXbmG9msiYIBuIkcbFdFm2kHiNKyoNE5+UCSmr8907Cq/rw==","signatures":[{"sig":"MEQCIGJynYaIb3eCs8dnaQt9QHXdlREKV6Pc3umy4nD0j6oEAiBWLrk3eHhjINOUagSIBNICjk3ZVjZ0r64P6ROr8nrPoA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":10098,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh2/OVCRA9TVsSAnZWagAA7tkQAIwfA3mO4I1sDgJ6tSLw\naNgY30IuuGOAbsgl5rtlZXLCGYeyufVBG9UHzDh/OnFxd/iCv43B8yCytTJ2\ntSiYQ0l5ZTS2do8wufwE9nitS6cfbJt8bLL7KrUArtXLQRA5gioNTyU8mxtF\nwV19LwdxbDOjxLZJJXYXdXotbYNXT0xeQLaFsUcfpqOB5+yqboiS5HzO8vUv\npqgzjCm8uewolv5gD6VKwhquSqY/Dt9ZIa17XtzHVAwV+UuL+WWPhQkFCP+L\nIDz2S0baI+S1A95Sn95e0ljqUcFCC4FX2vE5pm4/5dBz3322x6Vfiep8CEJL\nzOEimkfYNQ+FXl7ihUusQeLx4CUXMMxOga6rK1yQLaSmTsJpfQKS/n2aIadU\nvArev3+4weO3KhMeEIzG5fe8MylBG0KXoqIVcZMTILm6fLZZ1gddZgV93I+m\nSDftud3MuGo2uNoOkrw/jHRlLeE+HP25zXc0qnopESIEGt6WfJD4XPtXn0vh\nlk5CHc1ntpXTOnCRx2TgYhmCYQ07iJiN6wdE1mIhhEAvcoP/dPa6J8u1x2+P\nxwB/Vo6oQX29IHLS2NXdQzGGXLqOg+pl3hC+AV/F+R5eTfSSq4Uh0sZ6qZpx\nT3Up2q0E3/iSMkGEMCAahE1krdXKRZS4a40O9lEFrQdJMHxIEnNyKrtsL7cz\nMaXa\r\n=MQqR\r\n-----END PGP SIGNATURE-----\r\n"},"jest":{"rootDir":"src","transform":{"\\.[jt]sx?$":"@sucrase/jest-plugin"}},"main":"build/use-unmount-signal.js","gitHead":"30608f106d176a560623c5cc9bf9bbeacabc5153","scripts":{"test":"jest","build":"tsc","prepare":"rm -rf build && tsc"},"_npmUser":{"name":"ide","email":"ide+npm@jameside.com"},"repository":{"url":"git+https://github.com/expo/use-unmount-signal.git","type":"git"},"_npmVersion":"7.10.0","description":"A React Hook to cancel promises when a component is unmounted","directories":{},"_nodeVersion":"16.0.0","_hasShrinkwrap":false,"devDependencies":{"jest":"^26.6.3","react":"^17.0.2","typescript":"^4.2.4","@types/jest":"^26.0.22","@types/react":"^17.0.3","react-test-renderer":"^17.0.2","@sucrase/jest-plugin":"^2.1.0","@tsconfig/recommended":"^1.0.1","@testing-library/react-hooks":"^5.1.2"},"_npmOperationalInternal":{"tmp":"tmp/use-unmount-signal_1.0.0_1619131414870_0.6591540905939934","host":"s3://npm-registry-packages"}}},"time":{"created":"2021-04-22T22:43:34.829Z","modified":"2026-09-23T11:29:00.056Z","1.0.0":"2021-04-22T22:43:35.012Z"},"bugs":{"url":"https://github.com/expo/use-unmount-signal/issues"},"author":{"name":"Expo"},"license":"MIT","homepage":"https://github.com/expo/use-unmount-signal#readme","keywords":["react","hook","unmount","cancel","abortcontroller","abortsignal"],"repository":{"url":"git+https://github.com/expo/use-unmount-signal.git","type":"git"},"description":"A React Hook to cancel promises when a component is unmounted","maintainers":[{"email":"ide+npm@jameside.com","name":"ide"},{"email":"brentvatne@gmail.com","name":"brentvatne"},{"email":"support@expo.io","name":"expoadmin"},{"email":"exponent.team@gmail.com","name":"exponent"},{"email":"me@bycedric.com","name":"bycedric"},{"email":"ckchien@gmail.com","name":"kudochien"},{"email":"hughesno1@gmail.com","name":"alanhughes"},{"email":"npm@tsapeta.com","name":"tsapeta"},{"email":"brent+expobotnpm@expo.io","name":"expo-bot"},{"email":"phil@kitten.sh","name":"philpl"},{"email":"ccheever@gmail.com","name":"ccheever"},{"email":"sz.dziedz@gmail.com","name":"szdziedzic"},{"email":"wschurman@gmail.com","name":"wschurman"}],"readme":"# use-unmount-signal [![Tests](https://github.com/expo/use-unmount-signal/actions/workflows/tests.yml/badge.svg)](https://github.com/expo/use-unmount-signal/actions/workflows/tests.yml) [![codecov](https://codecov.io/gh/expo/use-unmount-signal/branch/main/graph/badge.svg?token=6YVSvvk4zB)](https://codecov.io/gh/expo/use-unmount-signal)\n\n`useUnmountSignal` is a React Hook to cancel promises when a component is unmounted. It uses [the W3C-standard `AbortSignal` API](https://dom.spec.whatwg.org/#interface-AbortSignal) to notify compatible promises when the calling component is unmounted.\n\n## API\n\n### `useUnmountSignal(): AbortSignal`\n\nA React Hook that returns an `AbortSignal` object that is marked as aborted when the calling component is unmounted.\n\n## Example\n\n```jsx\nimport useUnmountSignal from 'use-unmount-signal';\n\nfunction Example() {\n  // useUnmountSignal returns an AbortSignal object that APIs like fetch accept\n  const unmountSignal = useUnmountSignal();\n  return (\n    <button\n      onClick={() =>\n        fetch('https://ping.example.com', { signal: unmountSignal })\n      }>\n      Ping\n    </button>\n  );\n}\n```\n\n### With async function event handlers\n\n```jsx\nimport { useState } from 'react';\nimport useUnmountSignal from 'use-unmount-signal';\n\nfunction Example() {\n  const unmountSignal = useUnmountSignal();\n  const [status, setStatus] = useState('ready');\n\n  async function handleClick({ signal }) {\n    if (signal.aborted) { throw new AbortError(); }\n\n    const response = await fetch('https://ping.example.com', { signal });\n    if (signal.aborted) { throw new AbortError(); }\n\n    // We are guaranteed that the component is still mounted at this point\n    if (response.ok) {\n      setState('OK');\n    } else {\n      setState(response.status);\n    }\n  }\n\n  return <button onClick={handleClick}>Ping {status}</button>;\n}\n```\n","readmeFilename":"README.md"}