React hook that sends an HTTP POST request containing a small amount of data when a page gets fully unloaded

use-unload-beacon

React hook that sends an HTTP POST request containing a small amount of data when a page gets fully unloaded.

Install

$ npm install use-unload-beacon

Usage

import useUnloadBeacon from "use-unload-beacon";

export default function App() {
  useUnloadBeacon("/api/trackunload", () =>
    JSON.stringify({
      some: "data",
    })
  );

  return <>...</>;
}

API

useUnloadBeacon(Url, BodyInit)

BodyInit

Type: string

BodyInit

Type: string | ReadableStream | Blob | BufferSource | FormData | URLSearchParams

or

Type: (event: Event) => BodyInit

Docs

License

The MIT License.

Maintainers

GitHub

View Github