Skip to content

Instantly share code, notes, and snippets.

@GalindoSVQ
Created November 4, 2023 07:52
Show Gist options
  • Save GalindoSVQ/d43488e341e0008103ae26dd10d1b237 to your computer and use it in GitHub Desktop.
Save GalindoSVQ/d43488e341e0008103ae26dd10d1b237 to your computer and use it in GitHub Desktop.
import * as React from 'react';
export default function useFavicon(faviconUrl: string) {
React.useEffect(() => {
let link = document.querySelector(`link[rel~="icon"]`);
if (!link) {
link = document.createElement('link');
link.type = 'image/x-icon';
link.rel = 'icon';
link.href = faviconUrl;
document.head.appendChild(link);
} else {
link.href = faviconUrl;
}
}, [faviconUrl]);
}
@GalindoSVQ
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment