{
  "url": "https://unifast.dev/ja/docs/packages/react/compile-to-react/",
  "locale": "ja",
  "title": "compileToReact()",
  "description": "Markdown または MDX の入力をコンパイルし、React 要素に加えて frontmatter、診断、統計、TOC を直接返します。",
  "section": "packages",
  "body": "```ts\n\n```\n\n## シグネチャ\n\n```ts\nfunction compileToReact(\n  input: string,\n  options: CompileToReactOptions,\n): CompileToReactResult\n```\n\n## パラメータ\n\n### input\n\n| プロパティ | 型 | デフォルト | 説明 |\n|----------|------|---------|-------------|\n| `input` | `string` | — | Markdown または MDX のソース |\n\n### options\n\ncompile オプションに React 固有の設定を加えたものです\n\n| プロパティ | 型 | デフォルト | 説明 |\n|----------|------|---------|-------------|\n| `createElement` | `CreateElement` | — | React の createElement 関数 |\n| `Fragment` | `unknown` | — | React の Fragment コンポーネント |\n| `components?` | `ComponentMap` | — | HTML タグ名から React コンポーネントへのマップ |\n\n> [`CompileOptions`](/docs/packages/core/overview) を拡張しているため、その他の compile オプションもすべて受け付けます。\n\n## 戻り値\n\n| プロパティ | 型 | 説明 |\n|----------|------|-------------|\n| `element` | `unknown` | ルートの React 要素 |\n| `frontmatter` | `Record<string, unknown>` | パース済みの frontmatter メタデータ |\n| `diagnostics` | `Diagnostic[]` | 警告とエラー |\n| `stats` | `{ parseMs, transformMs, emitMs }` | 処理時間の内訳 (ミリ秒) |\n| `toc` | `TocEntry[]` | 抽出された目次 |\n\n## 使い方\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## 使用例\n\n### 基本的な使い方\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### カスタムコンポーネントと組み合わせて使う\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### サーバーサイドレンダリング\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### frontmatter と 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"
    }
  ]
}
