On passing the dependencies from array to the 2nd parameter of useEffect
, eslint throws the following error
// inputs need to go as part of effects dependency
export function useEffectAsync(effect, inputs) {
useEffect(() => {
effect();
}, [...inputs, effect]);
}
React Hook useEffect has a spread element in its dependency array. This means we can't statically verify whether you've passed the correct dependencies
Usage:
useEffectAsync(async () => {
await dispatch(getData());
// set something once data is available
}
}, [dispatch]);