-
Notifications
You must be signed in to change notification settings - Fork 50.6k
Description
Please add an option to the configuration for the react-hooks/exhaustive-deps eslint rule to require a deps argument for all hooks that can take it.
This new configuration option would throw a warning/error (don't care about default) for the code below:
const Demo = ({ thing }) => {
useEffect(() => {
console.log(thing)
})
}
I am aware that this already throws an error:
const Demo = ({ thing }) => {
useEffect(() => {
console.log(thing)
}, [])
}
This request is specifically concerning the case where no second argument is passed to hooks like useEffect, useCallback, useMemo, etc.
The configuration would be used in a way similar to this:
'react-hooks/exhaustive-deps': ['warn', {alwaysRequireDeps: true }]
Reasoning:
I can't think of a scenario where firing the callback of useEffect on every render is desired. An intentional eslint-disable-next-line is acceptable if this scenario arises.
A missing deps arg can cause sneaky bugs.