Files
probo/packages/hooks/src/useFavicon.ts
2026-02-02 13:32:57 +04:00

25 lines
641 B
TypeScript

import { useEffect } from "react";
export function useFavicon(faviconUrl?: string | null) {
useEffect(() => {
if (!faviconUrl) return;
let favicon: HTMLLinkElement;
const existingFavicon = document.getElementById("favicon") as (HTMLLinkElement | null);
if (existingFavicon) {
favicon = existingFavicon
favicon.href = faviconUrl;
} else {
favicon = document.createElement("link");
favicon.id = "favicon";
favicon.rel = "icon";
favicon.href = faviconUrl;
document.head.appendChild(favicon);
}
return () => {
favicon.href = "/favicons/favicon.ico";
}
});
}