diff --git a/packages/eslint-plugin-react-hooks/__tests__/ESLintRuleExhaustiveDeps-test.js b/packages/eslint-plugin-react-hooks/__tests__/ESLintRuleExhaustiveDeps-test.js index 9d20d062461fe..47c1a16d2ff65 100644 --- a/packages/eslint-plugin-react-hooks/__tests__/ESLintRuleExhaustiveDeps-test.js +++ b/packages/eslint-plugin-react-hooks/__tests__/ESLintRuleExhaustiveDeps-test.js @@ -1755,6 +1755,38 @@ const tests = { }, ], }, + { + code: normalizeIndent` + function MyComponent({ history }) { + useEffect(() => { + return [ + history?.foo + ]; + }, [history?.foo]); + } + `, + errors: [ + { + message: + "React Hook useEffect has a missing dependency: 'history?.foo'. " + + 'Either include it or remove the dependency array.', + suggestions: [ + { + desc: 'Update the dependencies array to be: [history?.foo]', + output: normalizeIndent` + function MyComponent({ history }) { + useEffect(() => { + return [ + history?.foo + ]; + }, [history?.foo]); + } + `, + }, + ], + }, + ], + }, { code: normalizeIndent` function MyComponent() {