{
  "url": "https://unifast.dev/de/docs/packages/react/compile-to-react/",
  "locale": "de",
  "title": "compileToReact()",
  "description": "Kompiliert Markdown- oder MDX-Eingaben und gibt direkt React-Elemente zusammen mit Frontmatter, Diagnostik, Statistiken und TOC zurück.",
  "section": "packages",
  "body": "```ts\n\n```\n\n## Signatur\n\n```ts\nfunction compileToReact(\n  input: string,\n  options: CompileToReactOptions,\n): CompileToReactResult\n```\n\n## Parameter\n\n### input\n\n| Eigenschaft | Typ | Standard | Beschreibung |\n|----------|------|---------|-------------|\n| `input` | `string` | — | Markdown- oder MDX-Quelle |\n\n### options\n\nKompilierungsoptionen plus React-spezifische Konfiguration\n\n| Eigenschaft | Typ | Standard | Beschreibung |\n|----------|------|---------|-------------|\n| `createElement` | `CreateElement` | — | Die `createElement`-Funktion von React |\n| `Fragment` | `unknown` | — | Die `Fragment`-Komponente von React |\n| `components?` | `ComponentMap` | — | Zuordnung von HTML-Tag-Namen zu React-Komponenten |\n\n> Erweitert [`CompileOptions`](/docs/packages/core/overview) – alle weiteren Kompilierungsoptionen werden ebenfalls akzeptiert.\n\n## Rückgabewert\n\n| Eigenschaft | Typ | Beschreibung |\n|----------|------|-------------|\n| `element` | `unknown` | Das React-Wurzelelement |\n| `frontmatter` | `Record<string, unknown>` | Geparste Frontmatter-Metadaten |\n| `diagnostics` | `Diagnostic[]` | Warnungen und Fehler |\n| `stats` | `{ parseMs, transformMs, emitMs }` | Zeitaufschlüsselung (ms) |\n| `toc` | `TocEntry[]` | Extrahiertes Inhaltsverzeichnis |\n\n## Verwendung\n\n```tsx\n\nconst { element, frontmatter: fm, toc: tocEntries, diagnostics, stats } = compileToReact(\n  md,\n  {\n    createElement,\n    Fragment,\n    components: {\n      h1: ({ children, ...props }) => <h1 className=\"title\" {...props}>{children}</h1>,\n      a: ({ children, ...props }) => <a target=\"_blank\" {...props}>{children}</a>,\n    },\n    plugins: [gfm(), frontmatter(), toc()],\n  },\n);\n```\n\n## Beispiele\n\n### Einfache Verwendung\n\n```tsx\n\nconst { element } = compileToReact(\n  \"# Hello, **world**!\",\n  { createElement, Fragment },\n);\n\nfunction Page() {\n  return <div>{element}</div>;\n}\n```\n\n### Mit benutzerdefinierten Komponenten\n\n```tsx\n\nconst { element } = compileToReact(md, {\n  createElement,\n  Fragment,\n  components: {\n    h1: ({ children, ...props }) => (\n      <h1 className=\"text-4xl font-bold\" {...props}>{children}</h1>\n    ),\n    a: ({ children, ...props }) => (\n      <a className=\"text-blue-500 underline\" target=\"_blank\" {...props}>{children}</a>\n    ),\n    code: ({ children, ...props }) => (\n      <code className=\"bg-gray-100 rounded px-1\" {...props}>{children}</code>\n    ),\n  },\n});\n```\n\n### Server-seitiges Rendering\n\n```tsx\n\nconst { element } = compileToReact(md, { createElement, Fragment });\nconst html = renderToString(element);\n\nconsole.log(html);\n// Rendered HTML string for SSR\n```\n\n### Verwendung von Frontmatter und TOC\n\n```tsx\n\nconst md = `---\ntitle: My Page\n---\n\n# Introduction\n\n## Setup\n\n## Usage\n`;\n\nconst result = compileToReact(md, {\n  createElement,\n  Fragment,\n  plugins: [frontmatter(), toc()],\n});\n\nconsole.log(result.frontmatter);\n// { title: \"My Page\" }\n\nconsole.log(result.toc);\n// [\n//   { depth: 1, text: \"Introduction\", slug: \"introduction\" },\n//   { depth: 2, text: \"Setup\", slug: \"setup\" },\n//   { depth: 2, text: \"Usage\", slug: \"usage\" },\n// ]\n```",
  "alternates": [
    {
      "locale": "en",
      "url": "https://unifast.dev/docs/packages/react/compile-to-react/",
      "api": "https://unifast.dev//api/docs/packages/react/compile-to-react.json"
    },
    {
      "locale": "ja",
      "url": "https://unifast.dev/ja/docs/packages/react/compile-to-react/",
      "api": "https://unifast.dev//api/ja/docs/packages/react/compile-to-react.json"
    },
    {
      "locale": "zh-CN",
      "url": "https://unifast.dev/zh-CN/docs/packages/react/compile-to-react/",
      "api": "https://unifast.dev//api/zh-CN/docs/packages/react/compile-to-react.json"
    },
    {
      "locale": "zh-TW",
      "url": "https://unifast.dev/zh-TW/docs/packages/react/compile-to-react/",
      "api": "https://unifast.dev//api/zh-TW/docs/packages/react/compile-to-react.json"
    },
    {
      "locale": "ko",
      "url": "https://unifast.dev/ko/docs/packages/react/compile-to-react/",
      "api": "https://unifast.dev//api/ko/docs/packages/react/compile-to-react.json"
    },
    {
      "locale": "fr",
      "url": "https://unifast.dev/fr/docs/packages/react/compile-to-react/",
      "api": "https://unifast.dev//api/fr/docs/packages/react/compile-to-react.json"
    },
    {
      "locale": "it",
      "url": "https://unifast.dev/it/docs/packages/react/compile-to-react/",
      "api": "https://unifast.dev//api/it/docs/packages/react/compile-to-react.json"
    },
    {
      "locale": "es",
      "url": "https://unifast.dev/es/docs/packages/react/compile-to-react/",
      "api": "https://unifast.dev//api/es/docs/packages/react/compile-to-react.json"
    },
    {
      "locale": "pt-BR",
      "url": "https://unifast.dev/pt-BR/docs/packages/react/compile-to-react/",
      "api": "https://unifast.dev//api/pt-BR/docs/packages/react/compile-to-react.json"
    },
    {
      "locale": "de",
      "url": "https://unifast.dev/de/docs/packages/react/compile-to-react/",
      "api": "https://unifast.dev//api/de/docs/packages/react/compile-to-react.json"
    },
    {
      "locale": "ru",
      "url": "https://unifast.dev/ru/docs/packages/react/compile-to-react/",
      "api": "https://unifast.dev//api/ru/docs/packages/react/compile-to-react.json"
    },
    {
      "locale": "hi",
      "url": "https://unifast.dev/hi/docs/packages/react/compile-to-react/",
      "api": "https://unifast.dev//api/hi/docs/packages/react/compile-to-react.json"
    },
    {
      "locale": "id",
      "url": "https://unifast.dev/id/docs/packages/react/compile-to-react/",
      "api": "https://unifast.dev//api/id/docs/packages/react/compile-to-react.json"
    },
    {
      "locale": "tr",
      "url": "https://unifast.dev/tr/docs/packages/react/compile-to-react/",
      "api": "https://unifast.dev//api/tr/docs/packages/react/compile-to-react.json"
    },
    {
      "locale": "vi",
      "url": "https://unifast.dev/vi/docs/packages/react/compile-to-react/",
      "api": "https://unifast.dev//api/vi/docs/packages/react/compile-to-react.json"
    }
  ]
}
