Appearance
useFavicon
Reactive favicon
Demo
Usage
tsx
import { useFavicon } from '@reause/core'
const [icon, setIcon] = useFavicon()
setIcon('dark.png') // change current iconPassing 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 siteType 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