useFavicon

Dynamically update the favicon.

https://www.shaktools.com/shak-hooks
Browser

API Reference

Installation

terminal
pnpm add @shak-hooks/usehooks
import.ts
import { useFavicon } from "@shak-hooks/usehooks";
Source: packages/react/src/useFavicon.ts

Signature

signature.ts
export function useFavicon(href: string)

Parameters

NameTypeOptionalDefault
hrefstringNo-

Returns

unknown

Implementation

use-favicon.ts
1import { useEffect } from "react";
2
3export function useFavicon(href: string) {
4 useEffect(() => {
5 const link: HTMLLinkElement =
6 document.querySelector("link[rel*='icon']") ||
7 document.createElement("link");
8 link.type = "image/x-icon";
9 link.rel = "shortcut icon";
10 link.href = href;
11 document.getElementsByTagName("head")[0].appendChild(link);
12 }, [href]);
13}

Advertisement

Google Ads

Usage

example.tsx
1import { useFavicon } from "@shak-hooks/usehooks";
2
3const result = useFavicon("...");
4// result: unknown
5// Use values directly (React state).

Let‘s do great work together

Empowering creators with free, high-performance AI, SEO, and developer tools. Join thousands of users optimizing their workflow with Shak-Tools.

Tools10+ Free
UsersGlobal

Stay in the loop

Join our newsletter for the latest AI tools and updates.

ShakTools
© 2025 Shaktools. All Rights Reserved.Privacy Policy