Does useRouter from 'next/navigation' return a stable reference?
#78303
Replies: 2 comments
-
|
Yes it does. You can include it in your deps array and not worry about it changing. For some cases, consider |
Beta Was this translation helpful? Give feedback.
-
|
Yes β the Internally, the router is provided through a React Context ( So this is safe and lint-clean: useEffect(() => {
router.prefetch("/x");
}, [router]);Note: this is specific to |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Can I rely on the
AppRouterInstancereturned byuseRouterto always be the same object?As in:
behaves equivalently to:
Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions