Skip to content

How to handle Unknown Prop warning on aria/button for onPress? #3666

Answered by reidbarber
PixeledCode asked this question in Q&A
Discussion options

You must be logged in to vote

You're probably spreading all the props down to the button element. You'll want to spread only buttonProps:

import {useButton} from 'react-aria';
import {useRef} from 'react';

function Button(props) {
  let ref = useRef();
  let { buttonProps } = useButton(props, ref);
  let { children } = props;

  return (
    <button {...buttonProps} ref={ref}>
      {children}
    </button>
  );
}

or be intentional with what get's passed down so that it's only valid DOM props.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@PixeledCode
Comment options

Answer selected by PixeledCode
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