Skip to content

Commit 31f75cd

Browse files
committed
Add test for a constant construction used in multiple dependency arrays
1 parent 2b7ae4b commit 31f75cd

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

packages/eslint-plugin-react-hooks/__tests__/ESLintRuleExhaustiveDeps-test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7491,6 +7491,33 @@ const tests = {
74917491
},
74927492
],
74937493
},
7494+
{
7495+
code: normalizeIndent`
7496+
function Foo() {
7497+
const foo = {};
7498+
useLayoutEffect(() => {
7499+
console.log(foo);
7500+
}, [foo]);
7501+
useEffect(() => {
7502+
console.log(foo);
7503+
}, [foo]);
7504+
}
7505+
`,
7506+
errors: [
7507+
{
7508+
message:
7509+
"The 'foo' object makes the dependencies of useLayoutEffect Hook (at line 6) change on every render. " +
7510+
"To fix this, wrap the initialization of 'foo' in its own useMemo() Hook.",
7511+
suggestions: undefined,
7512+
},
7513+
{
7514+
message:
7515+
"The 'foo' object makes the dependencies of useEffect Hook (at line 9) change on every render. " +
7516+
"To fix this, wrap the initialization of 'foo' in its own useMemo() Hook.",
7517+
suggestions: undefined,
7518+
},
7519+
],
7520+
},
74947521
],
74957522
};
74967523

0 commit comments

Comments
 (0)