一个回调函数,当setState结束并重新呈现该组件时将被调用。

一些没有说出来的东西是setState是异步的,这就是为什么它需要一个第二个回调函数。通常情况下,最好使用另一种生命周期方法,而不是依赖这个回调函数,但是很高兴知道它存在。

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

 

相关文章:

  • 2021-10-17
  • 2021-09-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-20
猜你喜欢
  • 2021-08-17
  • 2022-02-07
  • 2021-09-06
  • 2021-11-04
  • 2021-04-01
  • 2022-12-23
  • 2022-02-07
相关资源
相似解决方案