- Published on
useFavicon Hook React

useFavicon Hook React
useFavicon Code and Usage
useFavicon is a hook to change the favicon dynamically.
import { useEffect } from "react";
const useFavicon = (url) => {
useEffect(() => {
const favicon = document.querySelector('link[rel="icon"]');
favicon.href = url;
}, [url]);
};
// Usage
const FaviconExample = () => {
useFavicon("path-to-your-favicon.ico");
return (
<div>
<p>Favicon has been updated.</p>
</div>
);
};