epicweb-dev / react-hooks

Learn React Hooks! 🎣 ⚛

Home Page:https://hooks.epicreact.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Thoughts arising from the optimization of useState

qu-chen-x opened this issue · comments

@kentcdodds
Hi Kent,I am Aimee.And I am a junior developer.
I've recently encountered some problems in learning react, and I hope I can get some help from you.
if a state of component has updated with the same value, I expect React will not actually rerender the component due to the optimation logic. In the demo below, component rerendered when state value change from 1 to 2, that's what I expected. However, changing the value of state from 2 to 2 will also cause component rendered.
Why does it cause the second rendering?That's I want to ask you.Looking forward to your reply.Thank you.
https://codesandbox.io/s/sweet-maxwell-29o28?file=/src/App.js
#90

Hi Aimee! Would you mind asking this in my office hours? Thanks!