1.0.0 • Published 4 years ago
@ej-hooks/use-before-leave v1.0.0
@ej-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 @ej-hooks/use-before-leave
npm
npm i @ej-hooks/use-before-leave
Usage
import React from 'react';
import useBeforeLeave from '@ej-hooks/use-before-leave';
function App() {
  const beforeLeave = () => console.log('User is leaving...');
  useBeforeLeave(beforeLeave);
  return <h1>Hello Nooks</h1>;
}Arguments
| Argument | Type | Description | Required | 
|---|---|---|---|
| onBeforeLeave | function | Function to be called when the mouse leaves the document | yes | 
1.0.0
4 years ago