/ client / src / components / favicon.tsx
favicon.tsx
 1  import { useEffect } from "react";
 2  
 3  /**
 4   * Renders a favicon element in the head of the HTML document with the specified URL.
 5   *
 6   * @param {string} props.url - The URL of the favicon image.
 7   * @return {JSX.Element} - An empty JSX element.
 8   */
 9  export function Favicon(props: { url: string }) {
10    useEffect(() => {
11      let link = document.querySelector("link[rel~='icon']") as HTMLLinkElement;
12      if (!link) {
13        link = document.createElement("link") as HTMLLinkElement;
14        link.rel = "icon";
15        document.getElementsByTagName("head")[0].appendChild(link);
16      }
17      link.href = props.url;
18    }, [props.url]);
19    return <></>;
20  }