Skip to content

Runtime API Examples

This page demonstrates usage of some of the runtime APIs provided by VitePress.

The main useData() API can be used to access site, theme, and page data for the current page. It works in both .md and .vue files:

md
<script setup>
import { useData } from 'vitepress'

const { theme, page, frontmatter } = useData()
</script>

## Results

### Theme Data

<pre>{{ theme }}</pre>

### Page Data

<pre>{{ page }}</pre>

### Page Frontmatter

<pre>{{ frontmatter }}</pre>

Results

Theme Data

{
  "nav": [
    {
      "text": "Home",
      "link": "/"
    },
    {
      "text": "Vite Express",
      "link": "/docs/vitepress/"
    }
  ],
  "sidebar": [
    {
      "text": "Typescript React",
      "link": "/docs/typescript-react/index.md",
      "items": [
        {
          "text": "Booklet TS in React",
          "link": "/docs/typescript-react/booklet-ts-in-react"
        },
        {
          "text": "Mastering React Custom Hooks",
          "link": "/docs/typescript-react/mastering-react-custom-hooks"
        },
        {
          "text": "Mastering TS React",
          "link": "/docs/typescript-react/mastering-ts-react"
        }
      ]
    },
    {
      "text": "React Context",
      "link": "/docs/react-context",
      "items": [
        {
          "text": "Intro",
          "link": "/docs/react-context/intro"
        },
        {
          "text": "React context - Ex1",
          "link": "/docs/examples/ex1"
        },
        {
          "text": "React context - Ex2",
          "link": "/docs/examples/ex2"
        },
        {
          "text": "React context - Ex3",
          "link": "/docs/examples/ex3"
        }
      ]
    },
    {
      "text": "Next React",
      "link": "/docs/next-react/index.md",
      "items": [
        {
          "text": "Nextjs App to PWA",
          "link": "/docs/next-react/nextjs-app-to-pwa"
        }
      ]
    },
    {
      "text": "React States Mngmnt",
      "items": [
        {
          "text": "Hookstate",
          "link": "/docs/react-states-mngmnt/hookstate/hookstate"
        },
        {
          "text": "Zustand",
          "link": "/docs/react-states-mngmnt/zustand/zustand"
        }
      ]
    },
    {
      "text": "Misc",
      "link": "/docs/misc",
      "items": [
        {
          "text": "Combining useReducer with TS",
          "link": "docs//misc/combining-useReducer-with-ts"
        },
        {
          "text": "DnD Kit",
          "link": "docs//misc/dnd-kit"
        },
        {
          "text": "JS TS Collections",
          "link": "/docs/misc/Js-ts-collections"
        },
        {
          "text": "React Lifecycles",
          "link": "/docs/misc/react-lifecycles"
        },
        {
          "text": "useMemo useCallback",
          "link": "/docs/misc/useMemo-useCallback"
        }
      ]
    },
    {
      "text": "Examples",
      "link": "/docs/examples",
      "items": [
        {
          "text": "Nextjs Action SWR",
          "link": "/docs/examples/nextjs-action-swr"
        },
        {
          "text": "Nextjs useParams",
          "link": "/docs/examples/nextjs-useParams"
        },
        {
          "text": "Shopping Cart Management",
          "link": "/docs/examples/shopping-cart-management"
        },
        {
          "text": "Smart Table Component",
          "link": "/docs/examples/smart-table-component"
        }
      ]
    },
    {
      "text": "Vitepress",
      "link": "/docs/vitepress/index.md",
      "items": [
        {
          "text": "API Examples",
          "link": "/docs/vitepress/api-examples"
        },
        {
          "text": "Markdown Examples",
          "link": "/docs/vitepress/markdown-examples"
        }
      ]
    }
  ],
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/vuejs/vitepress"
    }
  ]
}

Page Data

{
  "title": "Runtime API Examples",
  "description": "",
  "frontmatter": {
    "outline": "deep"
  },
  "headers": [],
  "relativePath": "docs/vitepress/api-examples.md",
  "filePath": "docs/vitepress/api-examples.md"
}

Page Frontmatter

{
  "outline": "deep"
}

More

Check out the documentation for the full list of runtime APIs.