import { useEffect } from "react";

const preventNav = evt => {
  evt.preventDefault();
  evt.returnValue = ""; // eslint-disable-line no-param-reassign
};

const usePreventNavigation = () =>
  useEffect(() => {
    window.addEventListener("beforeunload", preventNav);
    return () => window.removeEventListener("beforeunload", preventNav);
  }, []);

export default usePreventNavigation;
