React Hook useEffect has a missing dependency: 'list'

前端 未结 5 2147
一个人的身影
一个人的身影 2021-01-04 20:27

Once I run the below code, I get the following error:

React Hook useEffect has a missing dependency: \'list\'. Either include it or remove the depende

5条回答
  •  天涯浪人
    2021-01-04 21:12

    The dependency array - it's the second optional parameter in the useEffect function. React will recall function defined in the first parameter of useEffect function if parameters inside dependency array will changed from the previous render.

    Then you doesn't need to place list variable inside dependency array.

      useEffect(() => {
        // do some
    
        // eslint-disable-next-line react-hooks/exhaustive-deps
      }, [term]);
    

提交回复
热议问题