{
  "url": "https://unifast.dev/vi/docs/packages/react/overview/",
  "locale": "vi",
  "title": "@unifast/react",
  "description": "Chuyển đầu ra HAST của unifast thành các React element với khả năng ánh xạ component",
  "section": "packages",
  "body": "## Tổng quan\n\n`@unifast/react` chuyển đổi đầu ra HAST (HTML Abstract Syntax Tree) của unifast thành các React element. Nó cung cấp hai hàm chính:\n\n- [`compileToReact()`](/docs/packages/react/compile-to-react) - Cấp cao: biên dịch Markdown/MDX và trả về trực tiếp các React element\n- [`hastToReact()`](/docs/packages/react/hast-to-react) - Cấp thấp: chuyển cây HAST thành các React element\n\nGói này tự động xử lý việc đổi tên thuộc tính từ HTML sang React (`class` thành `className`, `for` thành `htmlFor`, v.v.) và parse chuỗi CSS style.\n\n## Cài đặt\n\nPeer dependency: `@unifast/node` là cần thiết cho `compileToReact`.\n\n## Định nghĩa kiểu\n\n### CompileToReactOptions\n\nKế thừa `CompileOptions` và bổ sung thêm các trường dành riêng cho React.\n\n| Thuộc tính | Kiểu | Mô tả |\n|----------|------|-------------|\n| `createElement` | `CreateElement` | Hàm `createElement` của React |\n| `Fragment` | `unknown` | Component `Fragment` của React |\n| `components?` | `ComponentMap` | Map từ tên thẻ HTML sang React component |\n| *(tất cả CompileOptions)* | - | Kế thừa từ `CompileOptions` |\n\n### CompileToReactResult\n\n| Thuộc tính | Kiểu | Mô tả |\n|----------|------|-------------|\n| `element` | `unknown` | React element gốc |\n| `frontmatter` | `Record<string, unknown>` | Metadata frontmatter đã được parse |\n| `diagnostics` | `Diagnostic[]` | Cảnh báo và lỗi |\n| `stats` | `{ parseMs, transformMs, emitMs }` | Thống kê thời gian (ms) |\n| `toc` | `TocEntry[]` | Mục lục đã được trích xuất |\n\n### HastToReactOptions\n\n| Thuộc tính | Kiểu | Mô tả |\n|----------|------|-------------|\n| `createElement` | `CreateElement` | Hàm `createElement` của React |\n| `Fragment` | `unknown` | Component `Fragment` của React |\n| `components?` | `ComponentMap` | Map từ tên thẻ HTML sang React component tùy chỉnh |\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### Chuyển đổi thuộc tính\n\n| Thuộc tính HTML | Prop React |\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\nCác chuỗi CSS `style` được tự động parse thành các đối tượng style của React (ví dụ, `\"font-size: 16px\"` trở thành `{ fontSize: \"16px\" }`).\n\n## Tổng hợp các export\n\n| Export | Loại | Mô tả |\n|--------|------|-------------|\n| `compileToReact` | function | Biên dịch Markdown/MDX thành các React element |\n| `hastToReact` | function | Chuyển HAST thành các React element |\n| `CompileToReactOptions` | type | Tùy chọn cho `compileToReact` |\n| `CompileToReactResult` | type | Kết quả của `compileToReact` |\n| `HastToReactOptions` | type | Tùy chọn cho `hastToReact` |\n| `CreateElement` | type | Chữ ký của React createElement |\n| `ComponentMap` | type | Map từ thẻ HTML sang component |",
  "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"
    }
  ]
}
