Ask questionsBug: react-hooks/exhaustive-deps lint rule not working as expected
This issue is related to the
react-hooks/exhaustive-deps not detecting a reasonable case of warnings regarding missing dependencies.
The App contains two Children (One is the "increment" button where clicking on it will increment the value and the other child have an alert button to show the current value) while showing the current value also in the Parent component.
React version: 16.12.0
Link to code example: https://codesandbox.io/s/react-fp-context-usecallback-deps-zsoet?file=/src/Child2.js
react-hooks/exhaustive-deps don't report a missing dependencies.
2- The alerted value is the initial value (0) because of the stale closure even when being updated.
To solve this you need to add the missing dependency as so:
The code will work but the lint rule wouldn't be happy to push "unnecessary" dependency as it claims!
To show warning when this dependency is missing in such a reasonable case.
Answer questions vkurchatkin
The warning is correct: useAlert is a custom hook and context is an external value, so it is not a valid dependency