Closed ghost closed 3 years ago
You are not creating a new object, when you do object = prevMenus
they are still the same
You could try to deep cloning your object with (or something like it):
object = JSON.parse(JSON.stringify(prevMenus))
The answer of @vkatatab is correct. Closing since the described behavior is expected.
https://github.com/facebook/react/issues/19181 is pretty much my issue, but I did not find any useful information there. I tried to fix it by assigning the prevState to another variable and then editing the new one, but it did not work
React version: 17.0.2
Steps To Reproduce
Use this code:
Link to code example:
https://codesandbox.io/s/stoic-mahavira-gp5wf?fontsize=14&hidenavigation=1&theme=dark
The current behavior
The h1 with "Hi!" does not re-render, even though I am creating a new object
The expected behavior
The h1 with "Hi!" should re-render every time toggle is called