# Function useBeforeUnload

- useBeforeUnload(callback, options?): void

- Setup a callback to be fired on the window's `beforeunload` event. This is useful for saving some data to `window.localStorage` just before the page refreshes.

  Note: The `callback` argument should be a function created with `React.useCallback()`.

  #### Parameters

  - callback: ((event) => any)
    - - (event): any

      - #### Parameters

        - event: BeforeUnloadEvent

        #### Returns any

  - `Optional` options: {
    capture?: boolean;
    }

    - ##### `Optional` capture?: boolean

  #### Returns void

  - Defined in common/temp/node_modules/.pnpm/react-router-dom@6.23.1_react-dom@18.3.1+react@18.3.1/node_modules/react-router-dom/dist/index.d.ts:292