DEV Community

Discussion on: UseEffect in React18

Collapse
 
sjtgshivam profile image
Shivam pandey • Edited

Adding more to it. Components were always rendered twice(in some cases) in previous versions of Strict mode as well can check this thread github.com/facebook/react/issues/1... . So whats the difference now?

When a component is rendered the states that are created in previous render are destroyed and new references to newly created state variables are used in the second render.

While when simulating a re-render after simulating no new state is created and older state is used so if we made some changes to state in useEffect those changes will reflect and will be used as initial state of "simulated re-render". This is the main difference now.

Please do not confuse between two different things.