reactjs / reactjs/react.dev

Does `dispatch` function identity change when passed in context? [Re: eslint-plugin-react-hooks]

オープン
#1,889 コメント 13 件 リアクション 12 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
JavaScript
スター
11.8k
フォーク
7.9k
平均マージ
1日 11時間
マージ済み PR(30日)
11

説明

Issue:
  • The docs for useReducer suggests omitting dispatch from the dependencies list of useEffect and useReducer.

    Note
    React guarantees that dispatch function identity is stable and won't change on re-renders. This is why it's safe to omit from the useEffect or useCallback dependency list.

  • The docs also recommend passing dispatch function from useReducer via context to avoid passing callbacks down a large component tree:

  • eslint-plugin-react-hooks warns if dispatch (that's been passed from context) is not added to useEffect dependencies list.

    This conflicts with the first point above (docs suggesting omitting dispatch from the dependencies list)

    React Hook useCallback has a missing dependency: 'dispatch'. Either include it or remove the dependency array.
    

Is this:

  • Expected behavior after passing dispatch through context - so the docs should have a small amendment for this scenario?
  • Or a bug in eslint-plugin-react-hooks?

Thanks for the help!!

Working Sample:

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、リンク先の useReducer と Hooks FAQ のドキュメントを読み、その後 CodeSandbox で警告を再現し、eslint-plugin-react-hooks の動作と比較してください。ドキュメントに明確化が必要なのか、またはプラグインの動作に別途修正が必要なのかを判断し、関連する結論を記録できれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
eslint, javascript, react
領域
documentation, tooling
issue の種類
ドキュメント
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。