Add/improve documentation for typing function components with access to children
オープン
まだ誰も着手していません。
- 主要言語
- JavaScript
- スター
- 11.8k
- フォーク
- 7.9k
- 平均マージ
- 1日 11時間
- マージ済み PR(30日)
- 11
説明
With the introduction of React Hooks, the documentation recommends using function components instead of class components in the future.
However, I wonder how to define and type the component's properties when I want to access children components. I have come up with this solution (I am using Typescript):
import * as React from "react";
import "./styles.css";
type MyWrapperCompProps = {
color: string;
children?: React.ReactNode;
};
function MyWrapperComp(props: MyWrapperCompProps) {
return <div style={{ backgroundColor: props.color }}>{props.children}</div>;
}
export default function App() {
return (
<div className="App">
<MyWrapperComp color="tan">
<h1>Hello World!</h1>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Porro, fuga.
</p>
</MyWrapperComp>
</div>
);
}
This seems to work, but I have a couple of questions:
- Is this the best practice to model wrapper components with children?
- Is
ReactNodethe correct, most general type forchildren? - How does React automagically know that the children are assigned to
props.children? Is this hardwired to the namechildrenor is there anything I should be aware of? - Is the above documented anywhere at all on the React website?
Thanks a lot in advance for your help.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
この issue の TypeScript によるラッパーコンポーネントの例から始め、関数コンポーネントと children に関する React ウェブサイトの既存のドキュメントを確認します。適切なドキュメントのエントリーポイントを特定し、関連するガイダンスが、型付け、ReactNode、props.children、およびその動作がドキュメント化されているかどうかという4つの質問に答えていることを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- react, typescript
- 領域
- documentation
- issue の種類
- ドキュメント
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- 説明が足りない
- 初心者へのやさしさ
- 35/100