Skip to main content

useFavicon

function useFavicon(href: string | null): void;

Sets the page's favicon to href, such as to show unread messages. null leaves the page's own icon. Every <link rel="icon"> in the head is pointed at href, with a type taken from its file extension (none for an unknown extension or a data: URL), and a link is added if there are none. When href becomes null or the component unmounts, the links go back to what they were and an added link is removed. Nothing happens on the server.

Example​

import { useFavicon } from "react-honey-hooks";

function Inbox({ unread }: { unread: number }) {
useFavicon(unread > 0 ? "/favicon-unread.svg" : null);
return <MessageList />;
}