Open sipec opened 1 month ago
The latest updates on your projects. Learn more about Vercel for Git ↗︎
Name | Status | Preview | Comments | Updated (UTC) |
---|---|---|---|---|
dev | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Jun 7, 2024 0:57am |
docs | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Jun 7, 2024 0:57am |
prod | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Jun 7, 2024 0:57am |
react always rerenders when you call
setState
. so once upon a time, someone wrote a hook that checks if the thing has changed before calling setState. nevermind whether this use case is common or whether the overhead of adding a ref is worth it. I honestly don't know! there are many places we send requests to the server or db on the first render of a component, so while rerendering UI is very cheap, rerendering at all may not be? did anyone actually profile this??anyways, to do the equality check you need to have an
if(state != newState)
before you callsetState()
which means you can't consistently dosetState((capturedState) => ...
correctly since the state inside the setState may differ from the state outside it, but what you really want to condition on is the inside state having changed, not the outside state.