React Strict Mode - Second render, different initial state ?
[Next.js 14]
I have a component that at the top of the function defines a Set of strings:
const matches = new Set<string>()
const matches = new Set<string>()
And then I do a bunch of loops and logic to add any matches that have been made prior, as I don't want any duplicate matches to be rendered further down in the code. Pretty straightforward.
What confuses me, is that with ReactStrictMode on (as per default), I currently get 0 matches , when it renders a second time.
And what also confuses me is that on the second render caused by strict mode, if I console log the values of the set right after where it's defined there seems to be an
[[entries]]
[[entries]]
property as seen in the image below that are the values that should be in the set from the first render.
Which seems to be the culprit, as I get exactly the right result of matches when I disable strict mode and only render once.
I'm confused as to to why it would store the old values from the previous render, and cause the component to not work on following renders?