The example in hooks-faq "is-there-something-like-forceupdate" is wrong
オープン
まだ誰も着手していません。
- 主要言語
- JavaScript
- スター
- 11.8k
- フォーク
- 7.9k
- 平均マージ
- 1日 11時間
- マージ済み PR(30日)
- 11
説明
Direct link: https://reactjs.org/docs/hooks-faq.html#is-there-something-like-forceupdate
The example says
const [ignored, forceUpdate] = useReducer(x => x + 1, 0);
function handleClick() {
forceUpdate();
}
But this makes typescript report an error. (The typescript types are provided by the react team itself right? otherwise I might need to file a bug with the team maintaining the types)
Possible fixes:
const [ignored, forceUpdate] = useReducer(x => x + 1, 0);
function handleClick() {
forceUpdate("something"); //I added an argument here
}
will pass the type checker
const [ignored, forceUpdate] = useState(0); //useState instead of useReducer
function handleClick() {
forceUpdate(x => x + 1); //calculate function
}
is also ok (and a bit nicer IMHO)
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンク先の Hooks FAQ セクション「Is there something like forceUpdate?」を開き、掲載されている useReducer の例を確認してください。TypeScript で例を検証し、issue で説明されている型チェックの代替方法のいずれかを使って更新してください。ドキュメントの例で報告された TypeScript エラーが発生しなくなれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript, react
- 領域
- documentation
- issue の種類
- ドキュメント
- 難易度
- 1/5
- 見積もり時間
- 1時間未満
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 45/100