-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Rules of hooks error in useLinkProps
#7028
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
Comments
Thanks for reporting. This seems like the correct thing to do. I'm not sure why we conditionally called it originally. Would you like to open a PR for it? |
Sure thing, I'll open a PR. Looking into it a bit further, since the type of |
@abeljohn Sadly that change broke my whole application after upgrading to React Aria Compoenents 1.5.0 as I'm using an object as type for |
Provide a general summary of the issue here
When a react-aria-components
Link
or any component usinguseLinkProps
has itshref
change to or from undefined, a React error is thrown due to conditionally calling a hook. This only happens when using a customuseHref
hook for client-side routing, as the defaultuseHref
implementation does not use any hooks internally.🤔 Expected Behavior?
The
href
prop should be able to switch between undefined and having a value with no errors thrown, when usingRouterProvider
with auseHref
hook (e.g. react-router).😯 Current Behavior
If
href
switches from having a value to undefined, React throws the errorShould have a queue. You are likely calling Hooks conditionally, which is not allowed. (https://react.dev/link/invalid-hook-call)
.If
href
switches from undefined to having a value,Cannot read properties of undefined (reading 'length')
is thrown from within React code (areHookInputsEqual
).💁 Possible Solution
It looks like calling
router.useHref
unconditionally inuseSyntheticLinkProps
anduseLinkProps
would fix it based on the stack traces.🔦 Context
No response
🖥️ Steps to Reproduce
https://codesandbox.io/p/sandbox/crazy-dubinsky-7p8hsy
Click either button to change the
href
prop of aLink
Version
"react-aria-components": "1.3.3"
What browsers are you seeing the problem on?
Chrome
If other, please specify.
No response
What operating system are you using?
macOS Sonoma 14.5
🧢 Your Company/Team
No response
🕷 Tracking Issue
No response
The text was updated successfully, but these errors were encountered: