ReactJS - Does render get called any time “setState” is called?

后端 未结 7 894
攒了一身酷
攒了一身酷 2020-11-22 14:51

Does React re-render all components and sub components every time setState() is called?

If so, why? I thought the idea was that React only rendered as li

7条回答
  •  隐瞒了意图╮
    2020-11-22 15:11

    It seems that the accepted answers are no longer the case when using React hooks. You can see in this code sandbox that the class component is rerendered when the state is set to the same value, while in the function component, setting the state to the same value doesn't cause a rerender.

    https://codesandbox.io/s/still-wave-wouk2?file=/src/App.js

提交回复
热议问题