Setting nested state make the other states change (their values didn't change) #2506
Replies: 1 comment 11 replies
-
Isn't it because of useLayoutEffect? useEffect(() => {
console.log('...');
}); |
Beta Was this translation helpful? Give feedback.
11 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Setting nested state make the other states change (their values didn't change)
Link to reproduction
https://codesandbox.io/p/sandbox/amazing-rhodes-6yp8c5?file=%2Fsrc%2FApp.tsx
Please view the console, you can see that the components that watch
count
re-render even thoughcount
is the same. Refresh the page in code sandbox make it work as expected but on my real machine it doesn't.Here is my console log no matter how many times I reload the page
(I'm using vite btw)
I did some research and found out that this piece of code was the problem, look at
count
in the useLayoutEffect dependencies, but I still think it's a bug cause the watched state literally didn't changeCheck List
Please do not ask questions in issues.
Please include a minimal reproduction.
Please check this if you're filing an issue regarding TypeScript.
create
is to be used ascreate<T>()(...)
and notcreate<T>(...)
.Beta Was this translation helpful? Give feedback.
All reactions