codesandbox-client icon indicating copy to clipboard operation
codesandbox-client copied to clipboard

React useEffect run twice even strictMode is closed

Open CurryYangxx opened this issue 1 year ago • 2 comments

🐛 bug report

Preflight Checklist

  • [x] I have read the Contributing Guidelines for this project.
  • [x] I agree to follow the Code of Conduct that this project adheres to.
  • [x] I have searched the issue tracker for an issue that matches the one I want to file, without success.

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

CurryYangxx avatar Apr 26 '24 08:04 CurryYangxx

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 avatar May 09 '24 07:05 alexnm

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

CurryYangxx avatar May 28 '24 02:05 CurryYangxx