Rehooks
Content

useTitle

A hook to change/update the page title.

useTitle

Usage

Component.tsx
import { useTitle } from "~/hooks/useTitle";
 
function Component() {
  const { title, changeTitle } = useTitle();
 
  return (
    <div>
      <h1>{title}</h1>
      <button onClick={() => changeTitle("New Title")}>Change Title</button>
    </div>
  );
}

API

useTitle

function useTitle(): UseTitleResult;

Returns an object containing the current page title and a function to update both the state and the document title.

Returns

NameTypeDescription
titlestringCurrent page title.
changeTitle(newTitle: string) => voidA function to update the page title.

On this page