This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

use-refresh-lock
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

use-refresh-lock

useRefreshLock - Ensure that user allow the browser to refresh

Installation

yarn add use-refresh-lock

Usage

Create a simple refresh lock

import { useRefreshLock } from 'use-refresh-lock'
 
// create a lock
const release = useRefreshLock()
 
// now when you refresh the browser, the browse will prompt an
// 'Change you made may not be save.' prompt (aka Chrome)
 
// release the lock, just call the `release` method returned by `useRefreshLock`
release()

Aditionally, you could provide a callback to useRefreshLock. Recommended to use only to call navigator.sendBeacon only.

See: https://developer.mozilla.org/en-US/docs/Web/API/Navigator/sendBeacon

import { useRefreshLock } from 'use-refresh-lock'
 
const release = useRefreshLock(function() {
    // execute before the page successfully unloaded/reloaded
    navigator.sendBeacon("/log", analyticsData);
})

License

License under MIT

Readme

Keywords

none

Package Sidebar

Install

npm i use-refresh-lock

Weekly Downloads

2

Version

0.0.3

License

MIT

Unpacked Size

10.3 kB

Total Files

13

Last publish

Collaborators

  • andrewalex