Prefer functional updates version in hooks documentation
まだ誰も着手していません。
- 主要言語
- JavaScript
- スター
- 11.8k
- フォーク
- 7.9k
- 平均マージ
- 1日 11時間
- マージ済み PR(30日)
- 11
説明
Currently React hooks documentation at section Updating state is using a counter example for bot hooks and class based components. To recap:
In a class, we need to call this.setState() to update the count state:
<button onClick={() => this.setState({ count: this.state.count + 1 })}>
Click me
</button>
In a function, we already have setCount and count as variables so we don’t need this:
<button onClick={() => setCount(count + 1)}>
Click me
</button>
Although I can understand than this documentation must be simple and this example is really straightforward, isn't this a bad patter? Modifying state with a value based on old state?
The Functional update version is documented few pages after this example.
I'm wondering if:
- this example must be changed (although is probably the best type of example for state), or
- a warning box should be added to warn the user this is not the correct way to do.
To be more clear: I know there's nothing wrong with this specific example, but newcomers can quickly try to do something like calling setCount(count + 1) multiple times.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
hooks-state.html の Updating state セクションから始め、そのカウンターの例を hooks-reference.html の Functional updates セクションと比較してください。前の state に基づく繰り返しの更新について、例と説明的な警告のどちらがより適切に扱えるかを判断してください。既存の例と矛盾せず、ドキュメントが初心者を明確に導ければ完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript, react
- 領域
- documentation
- issue の種類
- ドキュメント
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100