Skip to content

useFavicon

Category
Export Size
378 B
Last Changed
5 days ago

Reactive favicon

Demo

Usage

tsx
import { 
useFavicon
} from '@reause/core'
const [
icon
,
setIcon
] =
useFavicon
()
setIcon
('dark.png') // change current icon

Passing a source ref

newIcon is a read-only value source and takes a plain string | null | undefined (upstream: MaybeRef<string | null | undefined>). Resolve a React ref at the call site; the returned setter owns the state from mount on, so a new argument is not adopted afterwards:

tsx
const [
icon
,
setIcon
] =
useFavicon
('dark.png')
setIcon
('light.png') // change the favicon
const [
refIcon
] =
useFavicon
(iconRef.current) // resolve a React ref at the call site

Type Declarations

ts
export interface UseFaviconOptions {
    baseUrl?: string;
    document?: Document | null;
    rel?: string;
}

export type UseFaviconReturn = [
    icon: string | null | undefined,
    setIcon: Dispatch<SetStateAction<string | null | undefined>>
]

export function useFavicon(newIcon?: string | null | undefined, options?: UseFaviconOptions): UseFaviconReturn

Source

Source · Demo · VueUse

Contributors

hairyf

Changelog

v0.1.0 on
61a60 - fix(core): resolve useFavicon audit findings (#556)
8fddc - chore!: remove all Vue-only Maybe* types and getter unions, adopt React Ref (#462)

Released under the MIT License. v0.1.8