Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.3k views
in Technique[技术] by (71.8m points)

useEffect循环

function handTable(s){
  console.log(s)
  异步setState()
  }
  ...
useEffect(
  ()=>handTable(params)
  , [])

请问我如上那样调用handTable为什么会一直循环,不加参数()就不会,该怎么改?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

有一种情况会导致你这种情况,你这个handTable函数实际上每次渲染都重新创建了,这种inline函数一般要用useCallback,这样就不会重新创建,而且useEffect里也会只执行一次。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...