react-use/src/useFavicon.ts
xobotyi b6993a6f95
feat(prettier): make prettier a part of eslint.
Also reduce max line width to 100. And remove `lint:types` step for
commit sequence, it bothers when committing incomplete (wip) changes.
2021-02-01 18:58:55 +03:00

15 lines
409 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;