Skip to content

Aria hooks and using {...rest} operator #3610

Answered by reidbarber
Agile-fox asked this question in Q&A
Discussion options

You must be logged in to vote

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:

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 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.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@Agile-fox
Comment options

@mryechkin
Comment options

@reidbarber
Comment options

Answer selected by Agile-fox
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants