npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

use-favicon

v2.0.0

Published

A React hook to add dynamic favicons to your application

Downloads

233

Readme

use-favicon

Declarative favicons for React. Pass a value, rerender to change it, and compose browser signals like dark-mode and away-state with your own logic.

import { useFavicon } from 'use-favicon';

export function App() {
  useFavicon('🦊');

  return <main>Hello</main>;
}

Install

pnpm add use-favicon
# or
npm install use-favicon
# or
yarn add use-favicon

Peer dependency: React 18 or 19.

How it works

useFavicon(value, options?) renders a favicon and returns void. To change it, rerender the component with a new value — same as any other React hook.

const [emoji, setEmoji] = useState('🙂');
useFavicon(emoji);

Supported values

The value type is inferred automatically:

| Value | Result | | --- | --- | | '🦊', '🚀', … | Emoji rendered inside an SVG | | '#f97316', 'rebeccapurple' | Solid CSS color tile | | ['#f97316', '#fb7185', '#38bdf8'] | Diagonal gradient | | '/icon.png', 'https://…/icon.svg' | Used directly as the favicon href | | { svg: '<svg…>' } | Raw SVG escape hatch |

Badges

Pass badge in the second argument to overlay a notification badge on emoji, color, or gradient favicons.

useFavicon('📥', { badge: unreadCount });

| badge value | Result | | --- | --- | | true | Red dot | | number or non-empty string | Text content (count or letter) | | { content, color?, position? } | Customized badge | | false, 0, or '' | No badge |

position accepts 'top right' (default), 'top left', 'bottom right', or 'bottom left'.

Dark mode and away state

useIsDark and useIsAway are standalone hooks. Combine them with your own state — no nested variant objects.

import { useFavicon, useIsAway, useIsDark } from 'use-favicon';

export function PresenceFavicon() {
  const isDark = useIsDark();
  const isAway = useIsAway();

  useFavicon(isAway ? '😴' : isDark ? '🌚' : '🌞');
}

Both hooks are SSR-safe and return false on the server.

Raw SVG

When you need full control, pass { svg }:

useFavicon({
  svg: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect width="100" height="100" rx="18" fill="#111827" /><path d="M28 72L50 24L72 72H61L50 47L39 72Z" fill="#f8fafc" /></svg>',
});

TypeScript

type FaviconValue = string | string[] | { svg: string };

type UseFaviconOptions = {
  badge?:
    | boolean
    | string
    | number
    | {
        content: string | number;
        color?: string;
        position?: 'top right' | 'top left' | 'bottom right' | 'bottom left';
      };
};

declare function useFavicon(value: FaviconValue, options?: UseFaviconOptions): void;

Named exports

  • useFavicon — set the favicon from a React component.
  • useIsDarktrue when the OS/browser prefers dark mode.
  • useIsAwaytrue when the tab is hidden.
  • buildFaviconSvg — pure function that returns the SVG string.
  • inferKind — detect what kind of value something is.
  • setFaviconHref — imperatively swap the favicon href.

Try it

The site/ workspace is a live playground for every feature. Run it with:

pnpm install
pnpm --filter use-favicon-site dev

Migrating from v1

If you used a previous version of this package, see MIGRATION.md for an old-to-new mapping of every changed feature.

License

MIT