Suppose I wanted to create a React Hook that's like useEffect, but it only runs when all the dependencies are non-null. It looks like this:
const useNonNullEffect = (callback: () => void, deps: any[]) => useEffect(() => {
if(deps.every(dep => dep !== null)) callback()
}, deps)
However, this fails to pass the "strict dependency" linter:
- It sees
callbackas an undeclared dependency. - I can't parse
deps, since it's not an array literal.
Is there some way to create hooks like this, where I take a set of dependencies from the user and forward them to the "real" hook?
(My actual use case is more complicated, this is just a simple expression of the problem for Stack Overflow purposes)
// eslint-disable-next-line react-hooks/exhaustive-depsright before the line wheredepsis and the warning should go away.callbackanddeps