Skip to content

Commit

Permalink
[eslint-plugin-react-hooks] reproduced bug with a test and fix it
Browse files Browse the repository at this point in the history
Since we only reserve `-Effect` suffix, react-hooks/exhaustive-deps is expected
to succeed without warning on a render helper which contains -use- in the middle
of it's name (but does NOT contain it as a prefix, since that would violate hook
naming convetion).
  • Loading branch information
Boris Sergeyev committed May 13, 2020
1 parent 0def77f commit 2607338
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,16 @@ const tests = {
}
`,
},
{
only: true,
code: normalizeIndent`
function MyComponent(props) {
return renderHelperConfusedWithEffect(() => {
console.log(props.foo);
}, []);
}
`,
},
{
// Valid because we don't care about hooks outside of components.
code: normalizeIndent`
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js
Original file line number Diff line number Diff line change
Expand Up @@ -1510,7 +1510,7 @@ function getReactiveHookCallbackIndex(calleeNode, options) {
// useImperativeHandle(ref, fn)
return 1;
default:
if (node === calleeNode && node.name.match(/use.+Effect$/)) {
if (node === calleeNode && node.name.match(/^use.+Effect$/)) {
return 0;
} else if (node === calleeNode && options && options.additionalHooks) {
// Allow the user to provide a regular expression which enables the lint to
Expand Down

0 comments on commit 2607338

Please sign in to comment.