[Mistake]: set-state-in-effect gives a wrong example of bad usage
オープン
まだ誰も着手していません。
type: typos
- 主要言語
- JavaScript
- スター
- 11.8k
- フォーク
- 7.9k
- 平均マージ
- 1日 11時間
- マージ済み PR(30日)
- 11
説明
Summary
Page
https://react.dev/reference/eslint-plugin-react-hooks/lints/set-state-in-render
Details
I want to sync state to a prop {/clamp-state-to-prop/}
A common problem is trying to "fix" state after it renders. Suppose you want to keep a counter from exceeding a
maxprop:
// ❌ Wrong: clamps during render
function Counter({max}) {
const [count, setCount] = useState(0);
if (count > max) {
setCount(max);
}
return (
<button onClick={() => setCount(count + 1)}>
{count}
</button>
);
}
As soon as
countexceedsmax, an infinite loop is triggered.
I think this Counter component can be rendered and clicked without issues.
The claim that an infinite loop will be triggered is incorrect.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
src/content/reference/eslint-plugin-react-hooks/lints/set-state-in-render.mdを読み、特にリンク先の70–91行と「I want to sync state to a prop」セクションを確認してください。Counterの例とその主張が、issueで説明されている挙動と一致するか確認してください。完了とは、例と説明が報告されたケースを正確に説明している状態です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript, react
- 領域
- documentation
- issue の種類
- ドキュメント
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 活発さ
- 静か
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 55/100