What happens when setState() function is called?

前端 未结 4 1303
礼貌的吻别
礼貌的吻别 2020-12-03 05:25

What does the setState() function run? Does it only run render()?

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-03 05:54

    Just an update to this answer: https://stackoverflow.com/a/45273993/7310034 (since lifeCycle methods are now updated)

    setState() will run functions in this order:

    getDerivedStateFromProps()

    shouldComponentUpdate()

    render()

    getSnapBeforeUpdate (if exists)

    componentDidUpdate()

    According to this: http://projects.wojtekmaj.pl/react-lifecycle-methods-diagram/

提交回复
热议问题