v6.0.35

use-favicon

Change favicon
Import

Usage

use-favicon appends <link /> element to head component with given favicon in React.useLayoutEffect hook. Hook is not called during server side rendering.

Call hook with favicon url (supported formats: .ico, .png, .svg and .gif) that should be set as favicon in any component. Hook is triggered every time url changes and value is not empty string (trailing whitespace is trimmed) or null.

import { useState } from 'react';
import { useFavicon } from '@asuikit/hooks';
import { Group, Button } from '@asuikit/core';
function Demo() {
const [favicon, setFavicon] = useState('https://srcalienswap.github.io/as-uikit/favicon.svg');
const setTwitterFavicon = () => setFavicon('https://twitter.com/favicon.ico');
const setMantineFavicon = () => setFavicon('https://srcalienswap.github.io/as-uikit/favicon.svg');
useFavicon(favicon);
return (
<Group position="center">
<Button onClick={setTwitterFavicon}>Twitter favicon</Button>
<Button onClick={setMantineFavicon}>Mantine favicon</Button>
</Group>
);
}

Definition

function useFavicon(url: string): void;