Created
November 4, 2023 07:52
-
-
Save GalindoSVQ/d43488e341e0008103ae26dd10d1b237 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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]); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Stackblitz link: https://stackblitz.com/edit/vitejs-vite-r1x4sd?file=src%2FuseFavicon.ts