codesandbox / codesandbox-client

An online IDE for rapid web development
https://codesandbox.io
Other
12.96k stars 2.26k forks source link

React useEffect run twice even strictMode is closed #8434

Open CurryYangxx opened 2 months ago

CurryYangxx commented 2 months ago

🐛 bug report

Preflight Checklist

Description of the problem

The useEffect sometimes running twice

image

How has this issue affected you? What are you trying to accomplish?

To Reproduce

refresh the browser in sandbox several times, and you can see the console.log() run twice

Link to sandbox: [link]() (optional)

https://codesandbox.io/p/devbox/black-hooks-znysly?file=%2Fsrc%2FApp.tsx%3A9%2C30

Your Environment

Software Name/Version
Сodesandbox https://codesandbox.io/
Browser Chrome
Operating System Macos
alexnm commented 1 month ago

hi, looking at the looking you sent, the console.log is not inside a useEffect, but rather inside the component, so it will run every time the component re-renders. Have you modified this since you wrote the issue?

CurryYangxx commented 1 month ago

hi, looking at the looking you sent, the console.log is not inside a useEffect, but rather inside the component, so it will run every time the component re-renders. Have you modified this since you wrote the issue?

@alexnm Hello, I am refering to the console.log in the Component.txs. The console.log(obj) is in useEffect, and I think it should only run once.

image