Skip to content

useUpdateEffect is not working as expected in react19 #2611

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
InfiniteXyy opened this issue Dec 11, 2024 · 2 comments · May be fixed by #2622
Open

useUpdateEffect is not working as expected in react19 #2611

InfiniteXyy opened this issue Dec 11, 2024 · 2 comments · May be fixed by #2622

Comments

@InfiniteXyy
Copy link

What is the current behavior?

Hi, I found that after upgrading to React 19, useUpdateEffect is triggered twice when the page mounts, which is not expected. We want the effect to be triggered only when the dependencies change.

When strictMode is removed, it seems this issue is resolved. However, in React 18, it works even with strictMode enabled. Additionally, I tried ahooks and the function with the same name in ahooks works normally.

Steps to reproduce it and if possible a minimal demo of the problem.

https://stackblitz.com/edit/vitejs-vite-ldfnvzh9?file=src%2FApp.tsx

What is the expected behavior?

The useUpdateEffect shouldn't be triggered when page is mounted

A little about versions:

  • OS: MacOS 15.1.1
  • Browser (vendor and version): Chrome Version 131.0.6778.110
  • React: 19.0.0
  • react-use: 17.6.0
  • Did this worked in the previous package version?: NO
@candymask0712
Copy link

@InfiniteXyy
Thanks for specific description.
I'd like to work on it. 😁

@httpete-broadcom
Copy link

I had to move to ahooks to get this working in react 19.

https://ahooks.js.org/hooks/use-update-effect/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants