Skip to content

Commit e27386f

Browse files
committed
Update useFavicon implementation
1 parent c90921a commit e27386f

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

index.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,17 @@ export function useDocumentTitle(title) {
266266

267267
export function useFavicon(url) {
268268
React.useEffect(() => {
269-
const link =
270-
document.querySelector("link[rel*='icon']") ||
271-
document.createElement("link");
272-
link.type = "image/x-icon";
273-
link.rel = "shortcut icon";
274-
link.href = url;
275-
document.getElementsByTagName("head")[0].appendChild(link);
269+
let link = document.querySelector(`link[rel~="icon"]`);
270+
271+
if (!link) {
272+
link = document.createElement("link");
273+
link.type = "image/x-icon";
274+
link.rel = "icon";
275+
link.href = url;
276+
document.head.appendChild(link);
277+
} else {
278+
link.href = url;
279+
}
276280
}, [url]);
277281
}
278282

0 commit comments

Comments
 (0)