Skip to content

armgit / ODS

Public Imported from GitHub
0

ODS V3 Pre-Release: Public testing and refinement ahead of the official V3 launch. Turn your PC, Mac, or Linux box into a private AI server.

505 B
Raw Blame
import { useEffect } from 'react'

/** Request the browser's leave-page confirmation only while edits may be lost. */
export function useBeforeUnload(enabled) {
  useEffect(() => {
    if (!enabled) return
    const protectDraft = (event) => {
      event.preventDefault()
      event.returnValue = true // Legacy browsers also require returnValue.
    }
    window.addEventListener('beforeunload', protectDraft)
    return () => window.removeEventListener('beforeunload', protectDraft)
  }, [enabled])
}