rooks
Version:
Collection of awesome react hooks
60 lines (59 loc) • 1.74 kB
TypeScript
/**
* useSuspenseFavicon
* @description Suspense-enabled hook for reading and updating the current favicon
* @see {@link https://rooks.vercel.app/docs/hooks/useSuspenseFavicon}
*/
type SameOriginFavicon = {
kind: "same-origin";
relativeHref: string;
href: string;
};
type ExternalFavicon = {
kind: "external";
url: string;
href: string;
};
type CurrentFavicon = SameOriginFavicon | ExternalFavicon | null;
type UpdateFaviconURLConfig = {
kind: "same-origin";
relativeHref: string;
} | {
kind: "external";
url: string;
};
type UnmountStrategy = "restore-originals" | "leave-as-is";
interface UseSuspenseFaviconOptions {
/**
* Controls how the hook cleans up the managed favicon when the last hook
* instance unmounts.
* @default "restore-originals"
*/
unmountStrategy?: UnmountStrategy;
}
interface UseSuspenseFaviconControls {
/**
* Updates the document favicon using a same-origin relative href or an
* external absolute URL.
*/
updateFaviconURL: (config: UpdateFaviconURLConfig) => void;
}
type UseSuspenseFaviconReturnValue = [
CurrentFavicon,
UseSuspenseFaviconControls
];
/**
* Clear the internal cache and restore managed DOM changes.
* Useful for tests.
*
* @internal
*/
export declare function clearCache(): void;
/**
* Suspense-enabled hook for reading and updating the current favicon.
*
* The hook suspends during the initial favicon discovery phase and then returns
* the current favicon resource along with controls for switching to a new
* same-origin or external favicon URL.
*/
declare function useSuspenseFavicon(options?: UseSuspenseFaviconOptions): UseSuspenseFaviconReturnValue;
export { useSuspenseFavicon };