import { useNavigate } from 'react-router-dom';
import { postLogOut } from './apiTools.jsx';

// New hook to make links use the react-router `navigate` method instead of default browser behavior.
export function useFixLinks() {
  // spread this return value on <a/> elements in order to make them navigate 
  const navigate = useNavigate();
  return { onClick: (e) => {
    if (e.target.tagName != "A") { return; }
    if (!e.target.href.includes(window.location.origin)) { return; }
    e.preventDefault();
    navigate(e.target.href.replace(window.location.origin, ""));
  }};
}