Aria hooks and using {...rest} operator #3610
-
Hello 👋 , 💥 Use case It happens with usage of all aria hooks. In switch for example additionally onChange and isSelected stops working. 🛠️ Fix ❓ My question |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
You don't want to spread all your component's props onto the element, because many props aren't valid DOM attributes like your error shows. We have a import {filterDOMProps, mergeProps} from '@react-aria/utils';
...
let ref = useRef(null);
let { buttonProps } = useButton(props, ref);
let domProps = filterDOMProps(props);
<button {...mergeProps(buttonProps, domProps)}>
...
</button And Also keep in mind that you can also pass anything you want down into the DOM element, after spreading the props returned by the react-aria hook. |
Beta Was this translation helpful? Give feedback.
You don't want to spread all your component's props onto the element, because many props aren't valid DOM attributes like your error shows.
We have a
filterDOMProps
that can help with this:And
mergeProps
is a utility that merges multiple props objects together, where event handlers are chained.Also keep in mind that you can also pass anything you want down into the DOM element, after spreading the props returned by the react-aria hook.