PHP Classes

File: src/hooks/useConfirmReload.tsx

Recommend this page to a friend!
  Classes of Maniruzzaman Akash   WordPress React Plugin Kit   src/hooks/useConfirmReload.tsx   Download  
File: src/hooks/useConfirmReload.tsx
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: WordPress React Plugin Kit
Environment to develop new WordPress plugins
Author: By
Last change:
Date: 2 years ago
Size: 563 bytes
 

Contents

Class file image Download
/** * External dependencies */ import { useEffect } from '@wordpress/element'; export default function useConfirmReload() { // If user tries to reload or close the tab, // then show him a warning useEffect(() => { const unloadCallback = (event: any) => { event.preventDefault(); event.returnValue = ''; return ''; }; window.addEventListener('beforeunload', unloadCallback); return () => window.removeEventListener('beforeunload', unloadCallback); }, []); return null; }