> ## Documentation Index
> Fetch the complete documentation index at: https://docs.morph-data.io/llms.txt
> Use this file to discover all available pages before exploring further.

# カスタムコンポーネントを作る

Morphのマークダウンファイルでは、**React**コンポーネントを使用することができます。

## カスタムコンポーネントを作成して、マークダウンファイルで使う

**1. tsxファイルを作ってコンポーネントをexportする**

srcディレクトリの中にtsxファイルを作成します。おすすめは、 `src/components` ディレクトリの中に作成することですが、どこでも構いません。

```tsx src/components/CustomComponent.tsx theme={"dark"}
// src/components/CustomComponent.tsx
import React from 'react';

export const CustomComponent: React.FC = () => {
  return (
    <div>
      <h1>Custom Component</h1>
    </div>
  );
};
```

**2. mdxファイルでカスタムコンポーネントを使う**

mdxファイルで、相対パスでtsxファイルをimportして使うことができます。

```tsx index.mdx theme={"dark"}
import { CustomComponent } from '../components/CustomComponent';

# カスタムコンポーネントのテスト

<CustomComponent />
```

## カスタムコンポーネントから、APIエンドポイントを利用する

カスタムコンポーネントの中から、Python関数を実行するには次のようにします。

このサンプルコードを理解するためには、[エイリアス](https://docs.morph-data.io/docs/ja/develop/guides/alias.md)、[loadData()](https://docs.morph-data.io/data-application/ja/morph-data-load-data.mdx)、[postData()](https://docs.morph-data.io/data-application/ja/morph-data-post-data.mdx)を参照してください。

```tsx src/components/CustomComponent.tsx theme={"dark"}
// src/components/CustomComponent.tsx
import React from "react";
import { loadData } from "@morph-data/components";

const metrics = loadData("example_metrics", "json"); # specify the alias and the format

export const LoadDataComp = () => {
  return (
    <div>
      <h1>Metrics</h1>
      <pre>{JSON.stringify(metrics, null, 2)}</pre>
    </div>
  );
};

const execBatch = postData("example_batch_process");

export const BatchButton = () => {
  const [variables, setVariables] = useState({});
  return (
    <button onClick={() => execBatch.run(variables)}>Execute Python</button>
  );
};
```

```tsx src/pages/index.mdx theme={"dark"}
import { LoadDataComp, BatchButton } from '../components/CustomComponent';

# カスタムコンポーネントのテスト

<LoadDataComp />

<BatchButton />
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.