Skip to content

Files

Latest commit

0d1b4ea · Jun 4, 2020

History

History
20 lines (13 loc) · 624 Bytes

re-14.md

File metadata and controls

20 lines (13 loc) · 624 Bytes

传入 setState 函数的第二个参数的作用是什么?

?> 英:What is the second argument that can optionally be passed to setState and what is its purpose?

答:

该函数会在setState函数调用完成并且组件开始重渲染的时候被调用,我们可以用该函数来监听渲染是否完成:

this.setState(
  { username: 'tylermcginnis33' },
  () => console.log('setState has finished and the component has re-rendered.')
)

参考资料:

题目来源

翻译文章