Playground

useDocumentTitle

Set document.title while a component is mounted, then restore it.

  • Sets the page title, which screen readers announce on navigation. Make each view title unique and meaningful.

Import

import '@monoline/css';
import {useDocumentTitle} from '@monoline/react';

Not installed yet? Pick a route.

Copies the source and its styles into your project.

npx monoline add use-document-title

Usage

import {useState} from 'react';
import {Button, useDocumentTitle, type Demo} from '@monoline/react';

function Demo() {
  const [n, setN] = useState(0);
  useDocumentTitle(n ? `(${n}) Monoline docs` : 'Monoline docs');
  return <Button onClick={() => setN(n + 1)}>Change the tab title ({n})</Button>;
}

<Demo />

Examples

Tab title

Behaviour

  • Sets the page title, which screen readers announce on navigation. Make each view title unique and meaningful.