mirror of
https://github.com/streamich/react-use.git
synced 2026-01-25 14:17:16 +00:00
14 lines
403 B
TypeScript
14 lines
403 B
TypeScript
import { useEffect } from 'react';
|
|
|
|
const useFavicon = (href: string) => {
|
|
useEffect(() => {
|
|
const link: HTMLLinkElement = document.querySelector("link[rel*='icon']") || document.createElement('link');
|
|
link.type = 'image/x-icon';
|
|
link.rel = 'shortcut icon';
|
|
link.href = href;
|
|
document.getElementsByTagName('head')[0].appendChild(link);
|
|
}, [href]);
|
|
};
|
|
|
|
export default useFavicon;
|