useDocumentTitle()

An easy way to set the title of the current document.

The Hook

1import { useIsomorphicLayoutEffect } from 'usehooks-ts'
2
3function useDocumentTitle(title: string): void {
4 useIsomorphicLayoutEffect(() => {
5 window.document.title = title
6 }, [title])
7}
8
9export default useDocumentTitle

Usage

1import { useDocumentTitle } from 'usehooks-ts'
2
3export default function Component() {
4 useDocumentTitle('foo bar')
5}

Edit on CodeSandbox

See a way to make this page better?
Edit there »