You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, the eslint-plugin does not validate dependencies for our custom useSelect and useSuspenseSelect hooks. This causes issues when developers miss a dependency when using those hooks.
To see this issue in action, find a useSelect usage in the code base, and add or remove an item in its dependencies array. There is no eslint error or warning about the dependencies. Note that you may need to reload the editor window to re-run eslint.
Here's an example: when we remove the clientId in the dependency array in the following useSelect usage, there is no warning or error.
What problem does this address?
useSelect
anduseSuspenseSelect
hooks in https://www.npmjs.com/package/@wordpress/data have dependencies array as their second parameters. The dependencies array is eventually passed touseCallback
in:gutenberg/packages/data/src/components/use-select/index.js
Line 183 in 8be5532
For normal React hooks like
useCallback
above, we already have'react-hooks/exhaustive-deps': 'warn'
in https://www.npmjs.com/package/@wordpress/eslint-plugin to help us declare all the dependencies.However, the eslint-plugin does not validate dependencies for our custom
useSelect
anduseSuspenseSelect
hooks. This causes issues when developers miss a dependency when using those hooks.To see this issue in action, find a
useSelect
usage in the code base, and add or remove an item in its dependencies array. There is no eslint error or warning about the dependencies. Note that you may need to reload the editor window to re-run eslint.Here's an example: when we remove the
clientId
in the dependency array in the followinguseSelect
usage, there is no warning or error.gutenberg/packages/block-library/src/search/edit.js
Lines 83 to 93 in 361f257
What is your proposed solution?
Make the eslint-plugin validate all the dependencies in
useSelect
anduseSuspenseSelect
hooks.This can be done by modifying the following line:
gutenberg/packages/eslint-plugin/configs/react.js
Line 37 in 8be5532
to:
Reference: https://www.npmjs.com/package/eslint-plugin-react-hooks#advanced-configuration
The text was updated successfully, but these errors were encountered: