Skip to main content

useFavicon

Set document favicon.

API

function useFavicon(
href: string | null,
options?: { mime?: string; restore?: boolean }
): void;

Params:

  • href: Required favicon url. If it is null, do nothing.
  • options: Options object.
    • options.mime: Specify the MIME type. Get automatically according to the href extname (support .png, .gif and .ico).
    • options.restore: Restore old favicon on the component unmount.

Example

import React from "react";
import { useFavicon } from "@lilib/hooks";

function Example() {
useFavicon("https://example.com/favicon.ico", { restore: true });
...
}