{
  "url": "https://unifast.dev/docs/packages/react/overview/",
  "locale": "en",
  "title": "@unifast/react",
  "description": "Convert unifast HAST output to React elements with component mapping",
  "section": "packages",
  "body": "## Overview\n\n`@unifast/react` converts unifast HAST (HTML Abstract Syntax Tree) output into React elements. It provides two main functions:\n\n- [`compileToReact()`](/docs/packages/react/compile-to-react) - High-level: compile Markdown/MDX and return React elements directly\n- [`hastToReact()`](/docs/packages/react/hast-to-react) - Low-level: convert a HAST tree into React elements\n\nThe package automatically handles HTML-to-React property renaming (`class` to `className`, `for` to `htmlFor`, etc.) and CSS style string parsing.\n\n## Installation\n\nPeer dependency: `@unifast/node` is required for `compileToReact`.\n\n## Type Definitions\n\n### CompileToReactOptions\n\nExtends `CompileOptions` with React-specific fields.\n\n| Property | Type | Description |\n|----------|------|-------------|\n| `createElement` | `CreateElement` | React's `createElement` function |\n| `Fragment` | `unknown` | React's `Fragment` component |\n| `components?` | `ComponentMap` | Map of HTML tag names to React components |\n| *(all CompileOptions)* | - | Inherited from `CompileOptions` |\n\n### CompileToReactResult\n\n| Property | Type | Description |\n|----------|------|-------------|\n| `element` | `unknown` | The root React element |\n| `frontmatter` | `Record<string, unknown>` | Parsed frontmatter metadata |\n| `diagnostics` | `Diagnostic[]` | Warnings and errors |\n| `stats` | `{ parseMs, transformMs, emitMs }` | Timing breakdown (ms) |\n| `toc` | `TocEntry[]` | Extracted table of contents |\n\n### HastToReactOptions\n\n| Property | Type | Description |\n|----------|------|-------------|\n| `createElement` | `CreateElement` | React's `createElement` function |\n| `Fragment` | `unknown` | React's `Fragment` component |\n| `components?` | `ComponentMap` | Map of HTML tag names to custom React components |\n\n### CreateElement\n\n```ts\ntype CreateElement = (type: any, props: any, ...children: any[]) => any;\n```\n\n### ComponentMap\n\n```ts\ntype ComponentMap = Record<string, unknown>;\n```\n\n### Property Conversion\n\n| HTML Attribute | React Prop |\n|---------------|------------|\n| `class` | `className` |\n| `for` | `htmlFor` |\n| `accesskey` | `accessKey` |\n| `autocomplete` | `autoComplete` |\n| `autofocus` | `autoFocus` |\n| `autoplay` | `autoPlay` |\n| `charset` | `charSet` |\n| `colspan` | `colSpan` |\n| `contenteditable` | `contentEditable` |\n| `crossorigin` | `crossOrigin` |\n| `datetime` | `dateTime` |\n| `enctype` | `encType` |\n| `formaction` | `formAction` |\n| `hreflang` | `hrefLang` |\n| `httpequiv` | `httpEquiv` |\n| `inputmode` | `inputMode` |\n| `maxlength` | `maxLength` |\n| `minlength` | `minLength` |\n| `novalidate` | `noValidate` |\n| `readonly` | `readOnly` |\n| `referrerpolicy` | `referrerPolicy` |\n| `rowspan` | `rowSpan` |\n| `spellcheck` | `spellCheck` |\n| `srcdoc` | `srcDoc` |\n| `srclang` | `srcLang` |\n| `srcset` | `srcSet` |\n| `tabindex` | `tabIndex` |\n| `usemap` | `useMap` |\n\nCSS `style` strings are automatically parsed into React style objects (e.g., `\"font-size: 16px\"` becomes `{ fontSize: \"16px\" }`).\n\n## Exports Summary\n\n| Export | Kind | Description |\n|--------|------|-------------|\n| `compileToReact` | function | Compile Markdown/MDX to React elements |\n| `hastToReact` | function | Convert HAST to React elements |\n| `CompileToReactOptions` | type | Options for `compileToReact` |\n| `CompileToReactResult` | type | Result of `compileToReact` |\n| `HastToReactOptions` | type | Options for `hastToReact` |\n| `CreateElement` | type | React createElement signature |\n| `ComponentMap` | type | HTML tag to component map |",
  "alternates": [
    {
      "locale": "en",
      "url": "https://unifast.dev/docs/packages/react/overview/",
      "api": "https://unifast.dev//api/docs/packages/react/overview.json"
    },
    {
      "locale": "ja",
      "url": "https://unifast.dev/ja/docs/packages/react/overview/",
      "api": "https://unifast.dev//api/ja/docs/packages/react/overview.json"
    },
    {
      "locale": "zh-CN",
      "url": "https://unifast.dev/zh-CN/docs/packages/react/overview/",
      "api": "https://unifast.dev//api/zh-CN/docs/packages/react/overview.json"
    },
    {
      "locale": "zh-TW",
      "url": "https://unifast.dev/zh-TW/docs/packages/react/overview/",
      "api": "https://unifast.dev//api/zh-TW/docs/packages/react/overview.json"
    },
    {
      "locale": "ko",
      "url": "https://unifast.dev/ko/docs/packages/react/overview/",
      "api": "https://unifast.dev//api/ko/docs/packages/react/overview.json"
    },
    {
      "locale": "fr",
      "url": "https://unifast.dev/fr/docs/packages/react/overview/",
      "api": "https://unifast.dev//api/fr/docs/packages/react/overview.json"
    },
    {
      "locale": "it",
      "url": "https://unifast.dev/it/docs/packages/react/overview/",
      "api": "https://unifast.dev//api/it/docs/packages/react/overview.json"
    },
    {
      "locale": "es",
      "url": "https://unifast.dev/es/docs/packages/react/overview/",
      "api": "https://unifast.dev//api/es/docs/packages/react/overview.json"
    },
    {
      "locale": "pt-BR",
      "url": "https://unifast.dev/pt-BR/docs/packages/react/overview/",
      "api": "https://unifast.dev//api/pt-BR/docs/packages/react/overview.json"
    },
    {
      "locale": "de",
      "url": "https://unifast.dev/de/docs/packages/react/overview/",
      "api": "https://unifast.dev//api/de/docs/packages/react/overview.json"
    },
    {
      "locale": "ru",
      "url": "https://unifast.dev/ru/docs/packages/react/overview/",
      "api": "https://unifast.dev//api/ru/docs/packages/react/overview.json"
    },
    {
      "locale": "hi",
      "url": "https://unifast.dev/hi/docs/packages/react/overview/",
      "api": "https://unifast.dev//api/hi/docs/packages/react/overview.json"
    },
    {
      "locale": "id",
      "url": "https://unifast.dev/id/docs/packages/react/overview/",
      "api": "https://unifast.dev//api/id/docs/packages/react/overview.json"
    },
    {
      "locale": "tr",
      "url": "https://unifast.dev/tr/docs/packages/react/overview/",
      "api": "https://unifast.dev//api/tr/docs/packages/react/overview.json"
    },
    {
      "locale": "vi",
      "url": "https://unifast.dev/vi/docs/packages/react/overview/",
      "api": "https://unifast.dev//api/vi/docs/packages/react/overview.json"
    }
  ]
}
