function Link(props) {
  const router = useRouter();
  const [childElm, setChildElm] = useState();
  const child = Children.only(props.children);

  const { href, as, scroll = true, shallow = false } = props;

  const shouldPrefetch = props.prefetch !== false;

  useEffect(() => {
    if (
      shouldPrefetch &&
      IntersectionObserver &&
      childElm &&
      childElm.tagName
    ) {
      const isPrefetched = prefetched[href + "%" + as];

      if (!isPrefetched) {
        return listenToIntersections(childElm, () => {
          prefetch(router, href, as);
        });
      }
    }
  }, [shouldPrefetch, childElm, href, as, router]);

  function linkClicked(e) {
    const { nodeName, target } = e.currentTarget;
    if (
      nodeName === "A" &&
      ((target && target !== "_self") ||
        e.metaKey ||
        e.ctrlKey ||
        e.shiftKey ||
        (e.nativeEvent && e.nativeEvent.which === 2))
    ) {
      // ignore click for new tab / new window behavior
      return;
    }

    if (!isLocal(href)) return;

    e.preventDefault();

    router.push(href, as, { scroll, shallow });
  }

  const childProps = {
    // Forward ref if the user has it set
    ref: (el) => {
      if (el) setChildElm(el);

      if (child && child.ref) {
        if (typeof child.ref === "function") child.ref(el);
        else if (typeof child.ref === "object") {
          child.ref.current = el;
        }
      }
    },
    // Forward onClick handler if the user has it set
    onClick: (e) => {
      if (child.props && typeof child.props.onClick === "function") {
        child.props.onClick(e);
      }

      if (!e.defaultPrevented) {
        linkClicked(e);
      }
    },
  };

  if (shouldPrefetch) {
    childProps.onMouseEnter = (e) => {
      if (child.props && typeof child.props.onMouseEnter === "function") {
        child.props.onMouseEnter(e);
      }

      prefetch(router, href, as, { priority: true });
    };
  }

  // If child is an <a> tag and doesn't have a href attribute, or if the 'passHref' property is
  // defined, we specify the current 'href', so that repetition is not needed by the user
  if (props.passHref || (child.type === "a" && !("href" in child.props))) {
    childProps.href = as || href;
  }

  return React.cloneElement(child, childProps);
}
Heavily-inspired by next/link

@param {object} props