1.0.2 • Published 3 years ago

@practical-react-hooks/use-before-leave v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

@practical-react-hooks/use-before-leave

React Hook to execute a function when the mouse leaves the page. Useful to show a popup or for analytics.

Installation

yarn

yarn add @practical-react-hooks/use-before-leave

npm

npm i @practical-react-hooks/use-before-leave

Usage

import React from "react";
import useBeforeLeave from "@practical-react-hooks/use-before-leave";

const App = () => {
  const beforeLeave = () => console.log("User is leaving...");
  useBeforeLeave(beforeLeave);
  return (
    <div className="App">
      <h1>Hello World</h1>
    </div>
  );
};

Arguments

ArgumentTypeDescriptionRequired
onBeforeLeavefunctionFunction to be called when the mouse leaves the documentyes