useTitle
A hook to reactively manage document.title
Loading...
Installation
npx shadcn@latest add @shadcnhooks/use-titleAPI
export interface UseTitleOptions {
/**
* Observe external changes to `document.title`.
* @default false
*/
observe?: boolean
/**
* Optional template for the final browser title.
* Use `%s` as the placeholder when providing a string template.
*/
titleTemplate?: string | ((title: string) => string)
}
/**
* Reactively read and update `document.title`.
*
* @param newTitle Optional initial/controlled title value.
* @param options Hook options.
*/
export function useTitle(
newTitle?: string | null,
options?: UseTitleOptions,
): readonly [string, Dispatch<SetStateAction<string>>]Credits
Last updated on