{
  "url": "https://unifast.dev/de/docs/packages/react/hast-to-react/",
  "locale": "de",
  "title": "hastToReact()",
  "description": "Konvertiert einen HAST-Wurzelknoten in React-Elemente. Die Low-Level-Funktion für Fälle, in denen Sie vollständige Kontrolle über die Kompilierungspipeline benötigen.",
  "section": "packages",
  "body": "```ts\n\n```\n\n## Signatur\n\n```ts\nfunction hastToReact(\n  hast: HastRoot,\n  options: HastToReactOptions,\n): unknown\n```\n\n## Parameter\n\n### hast\n\n| Eigenschaft | Typ | Standard | Beschreibung |\n|----------|------|---------|-------------|\n| `type` | `\"root\"` | — | Bezeichner des Knotentyps |\n| `children` | `HastNode[]` | — | Kindknoten des Baums |\n\n### options\n\nKonfiguration für die Erzeugung von React-Elementen\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 benutzerdefinierten React-Komponenten |\n\n## Verwendung\n\n```tsx\n\nconst result = compile(md, { outputKind: \"hast\" });\nconst hast: HastRoot = JSON.parse(result.output as string);\n\nconst element = hastToReact(hast, {\n  createElement,\n  Fragment,\n  components: {\n    pre: ({ children, ...props }) => <pre className=\"code-block\" {...props}>{children}</pre>,\n    a: ({ children, ...props }) => <a target=\"_blank\" rel=\"noopener\" {...props}>{children}</a>,\n  },\n});\n```\n\n## Beispiele\n\n### Einfache Verwendung\n\n```tsx\n\nconst result = compile(\"# Hello, **world**!\", { outputKind: \"hast\" });\nconst hast: HastRoot = JSON.parse(result.output as string);\nconst element = hastToReact(hast, { createElement, Fragment });\n\nfunction Page() {\n  return <div>{element}</div>;\n}\n```\n\n### Mit Shiki-hervorgehobenem HAST\n\n```tsx\n\nconst transformer = await createShikiTransformer({\n  themes: [\"github-dark\"],\n  langs: [\"typescript\"],\n});\n\nconst result = compile(md, { outputKind: \"hast\" });\nconst hast: HastRoot = JSON.parse(result.output as string);\nconst highlighted = transformer.transform(hast);\nconst element = hastToReact(highlighted, { createElement, Fragment });\n```\n\n### Server-seitiges Rendering\n\n```tsx\n\nconst result = compile(md, { outputKind: \"hast\" });\nconst hast: HastRoot = JSON.parse(result.output as string);\nconst element = hastToReact(hast, { createElement, Fragment });\nconst html = renderToString(element);\n\nconsole.log(html);\n// Rendered HTML string for SSR\n```\n\n## Verhalten\n\n- **Umbenennung von Eigenschaften:** HTML-Attribute werden in die entsprechenden React-Namen umbenannt (`class` zu `className`, `for` zu `htmlFor` usw.)\n- **Style-Parsing:** CSS-Style-Strings werden in React-Style-Objekte geparst\n- **className-Arrays:** HAST-`className`-Arrays werden mit Leerzeichen verbunden\n- **Boolesche Attribute:** `true` rendert das Attribut, `false`/`null`/`undefined` lässt es weg\n- **Raw-Knoten:** Werden als Inline-HTML gerendert – verwenden Sie das `sanitize`-Plugin (aus `@unifast/node`), wenn Sie nicht vertrauenswürdige Eingaben verarbeiten\n- **Kommentare und Doctype:** Werden ignoriert (geben `null` zurück)",
  "alternates": [
    {
      "locale": "en",
      "url": "https://unifast.dev/docs/packages/react/hast-to-react/",
      "api": "https://unifast.dev//api/docs/packages/react/hast-to-react.json"
    },
    {
      "locale": "ja",
      "url": "https://unifast.dev/ja/docs/packages/react/hast-to-react/",
      "api": "https://unifast.dev//api/ja/docs/packages/react/hast-to-react.json"
    },
    {
      "locale": "zh-CN",
      "url": "https://unifast.dev/zh-CN/docs/packages/react/hast-to-react/",
      "api": "https://unifast.dev//api/zh-CN/docs/packages/react/hast-to-react.json"
    },
    {
      "locale": "zh-TW",
      "url": "https://unifast.dev/zh-TW/docs/packages/react/hast-to-react/",
      "api": "https://unifast.dev//api/zh-TW/docs/packages/react/hast-to-react.json"
    },
    {
      "locale": "ko",
      "url": "https://unifast.dev/ko/docs/packages/react/hast-to-react/",
      "api": "https://unifast.dev//api/ko/docs/packages/react/hast-to-react.json"
    },
    {
      "locale": "fr",
      "url": "https://unifast.dev/fr/docs/packages/react/hast-to-react/",
      "api": "https://unifast.dev//api/fr/docs/packages/react/hast-to-react.json"
    },
    {
      "locale": "it",
      "url": "https://unifast.dev/it/docs/packages/react/hast-to-react/",
      "api": "https://unifast.dev//api/it/docs/packages/react/hast-to-react.json"
    },
    {
      "locale": "es",
      "url": "https://unifast.dev/es/docs/packages/react/hast-to-react/",
      "api": "https://unifast.dev//api/es/docs/packages/react/hast-to-react.json"
    },
    {
      "locale": "pt-BR",
      "url": "https://unifast.dev/pt-BR/docs/packages/react/hast-to-react/",
      "api": "https://unifast.dev//api/pt-BR/docs/packages/react/hast-to-react.json"
    },
    {
      "locale": "de",
      "url": "https://unifast.dev/de/docs/packages/react/hast-to-react/",
      "api": "https://unifast.dev//api/de/docs/packages/react/hast-to-react.json"
    },
    {
      "locale": "ru",
      "url": "https://unifast.dev/ru/docs/packages/react/hast-to-react/",
      "api": "https://unifast.dev//api/ru/docs/packages/react/hast-to-react.json"
    },
    {
      "locale": "hi",
      "url": "https://unifast.dev/hi/docs/packages/react/hast-to-react/",
      "api": "https://unifast.dev//api/hi/docs/packages/react/hast-to-react.json"
    },
    {
      "locale": "id",
      "url": "https://unifast.dev/id/docs/packages/react/hast-to-react/",
      "api": "https://unifast.dev//api/id/docs/packages/react/hast-to-react.json"
    },
    {
      "locale": "tr",
      "url": "https://unifast.dev/tr/docs/packages/react/hast-to-react/",
      "api": "https://unifast.dev//api/tr/docs/packages/react/hast-to-react.json"
    },
    {
      "locale": "vi",
      "url": "https://unifast.dev/vi/docs/packages/react/hast-to-react/",
      "api": "https://unifast.dev//api/vi/docs/packages/react/hast-to-react.json"
    }
  ]
}
