开发者社区> 问答> 正文

#React 回调函数作为参数的目的是什么setState()?

#React 回调函数作为参数的目的是什么setState()?

展开
收起
因为相信,所以看见。 2020-05-07 16:04:50 893 0
1 条回答
写回答
取消 提交回答
  • 阿里,我所有的向往

    setState完成并呈现组件时,将调用回调函数。由于setState()是异步的,因此回调函数可用于任何后期操作。

    注意:建议使用生命周期方法而不是此回调函数。

    setState({ name: 'John' }, () => console.log('The name has updated and component re-rendered'))
    
    2020-05-07 16:05:28
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
利用编译将 Vue 组件转成 React 组件 立即下载
React Native 全量化实践 立即下载
React Native项目实战优化之路 立即下载