2

在将依赖项从数组传递到 的第二个参数时useEffect,eslint 抛出以下错误

// 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

用法:

useEffectAsync(async () => {
        await dispatch(getData());
        // set something once data is available 
     }
 }, [dispatch]);
4

0 回答 0