🚧 Rspress 2.0 document is under development
close

useFrontmatter

useFrontmatter returns the frontmatter of the current page in a convenient object.

  • Type: () => { frontmatter: FrontMatterMeta }

Example: render a custom badge when the page is marked as beta in frontmatter.

import { useFrontmatter } from '@rspress/core/runtime';

export default function BetaBadge() {
  const { frontmatter } = useFrontmatter();
  return frontmatter.beta ? <span>Beta</span> : null;
}

Combine with usePage when you also need other page metadata (title, route, toc, etc.).