@feca-hooks/use-prevent-leave

1.0.1 • Public • Published

@feca-hooks/use-prevent-leave

React Hook to prompt the user for confirmation before leaving the page.


How to Install

yarn

yarn add @feca-hooks/use-prevent-leave

npm

npm i @feca-hooks/use-prevent-leave


Usage

Code

import React from "react";
import usePreventLeave from "@feca-hooks/use-prevent-leave";

function App() {
  const { enablePrevent, disablePrevent } = usePreventLeave();

  const fetchData = async () => {
    enablePrevent();
    await fetchApi();
    disablePrevent();
  };

  return <button onClick={fetchData}>Fetch</button>;
}

Return

Return value Type Description
enable/disable Prevent object An object containing functions enablePrevent and disablePrevent, use this functions to enable/disable the leaving prevention.

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i @feca-hooks/use-prevent-leave

      Weekly Downloads

      4

      Version

      1.0.1

      License

      MIT

      Unpacked Size

      2.18 kB

      Total Files

      4

      Last publish

      Collaborators

      • pshtony1