# Children

`components`配下に`PrimaryButton.tsx`を作成します。

以下リンクのボタンのcssを利用して、記述します。

{% embed url="<https://getbootstrap.jp/docs/5.3/components/buttons/>" %}

{% code title="PrimaryButton.tsx◎" %}

```tsx
export const Button = () => {
  return (
    <button type="button" className="btn btn-primary">
      Primary
    </button>
  );
};
```

{% endcode %}

そして、primaryの部分を変えて何度も利用するため、前セクションで説明したようなpropsにて受け取るのもいいですが、`children`というpropsの受け取り方があります。`children`という変数名にてporpsを受け取るようにしましょう。

<pre class="language-tsx" data-title="PrimaryButton.tsx◎"><code class="lang-tsx"><strong>type Props = {
</strong><strong>  children: string;
</strong><strong>};
</strong>
<strong>export const PrimaryButton = ({ children }: Props) => {
</strong>  return (
    &#x3C;button type="button" className="btn btn-primary">
      {children}
    &#x3C;/button>
  );
};
</code></pre>

上記を呼び出してみましょう。`children`を受け取る場合は、HTMLタグのように`<PrimaryButton>button1</PrimaryButton>`と開始タグ、終了タグを記述して、`button1`の部分が`children`で受け取る値になります。

<pre class="language-tsx" data-title="PrimaryButton.tsx◎"><code class="lang-tsx">import { Breadcrumb } from "./components/BreadCrumb";
<strong>import { PrimaryButton } from "./components/Button";
</strong>...
    &#x3C;div>
      &#x3C;Breadcrumb items={items1} />
      &#x3C;Breadcrumb items={items2} />
      &#x3C;UserDetail />
<strong>      &#x3C;PrimaryButton>button1&#x3C;/PrimaryButton>
</strong><strong>      &#x3C;PrimaryButton>button2&#x3C;/PrimaryButton>
</strong>    &#x3C;/div>
  );
};
...
</code></pre>

上記にて以下のように確認できるかと思います。

<figure><img src="https://1869761657-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcUBbYqol4PMzZJggiMqV%2Fuploads%2Fd2iMJFI5zowPdNJJDj5D%2F202312073.png?alt=media&#x26;token=c3d46b98-4c6f-4784-92f2-a2062b16ea9e" alt=""><figcaption></figcaption></figure>

`children`は子要素を全て受け取ることができるので、HTMLタグも渡すことできます。

```tsx
<PrimaryButton>button<span>1</span></PrimaryButton>
```

上記のようにタグを渡す場合は、PrimaryButtonの`children`の型を`ReactNode`という方にする必要があります。

```tsx
import { ReactNode } from "react";

type Props = {
  children: ReactNode;
};
```
