@trashpanda001/helpers
    Preparing search index...

    Function useBeforeUnload

    • Registers a beforeunload event listener that invokes the given callback.

      The callback can invoke event.preventDefault() and set event.returnValue to a string

      Parameters

      • callback: (event: BeforeUnloadEvent) => void

        callback handler

      • enabled: boolean = true

        whether to register the event listener

      Returns void

      Prompt the user before leaving the page.

      import { useBeforeUnload } from "@trashpanda001/helpers/react"

      function Component() {
      useBeforeUnload((event) => {
      event.preventDefault()
      event.returnValue = "Are you sure you want to leave?"
      })
      return <div>Page</div>
      }