[v6] useNavigate triggers useEffect #8465
Replies: 4 comments 1 reply
-
We've run into this problem in our team too. It'd be nice to have a |
Beta Was this translation helpful? Give feedback.
-
I use this snippet:
|
Beta Was this translation helpful? Give feedback.
-
Oh yeah, the good old trick. I wonder why it is not the default that React do this for us for all callbacks. Anyway, thanks. Indeed, it's a good workaround. |
Beta Was this translation helpful? Give feedback.
-
FYI: With 6.4, redirecting in loaders/actions is usually preferred over |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I am currently porting from v5 to v6 and found out, that
useNavigate()
is calling useEffect, when used as a dependency (in contrast touseHistory()
before):You can find a Code sample here: https://codesandbox.io/s/eloquent-rosalind-wi2ch
I guess this is because of the relative navigation, right?
When I omit the navigate in the dependencies and navigate to an absolute path, I guess it would still work?
Have you got other solutions to avoid those not wanted calls?
Beta Was this translation helpful? Give feedback.
All reactions