How to use filterDOMProps?
#7979
Replies: 2 comments 6 replies
-
|
Thanks for the dicussion.
If you're just curious what it does, it allows through Because it's undocumented and therefore considered private, we do not guarantee its API in semver. If there's a strong reason, we can discuss making it public. |
Beta Was this translation helpful? Give feedback.
-
|
Maintainer of a project which uses react-aria directly with native HTML elements here. I haven't seen many other examples of folks handling prop pollution, most are destructuring the react-aria hooks to omit the unused props before spreading onto the native elements. This works just fine, but it does require us to suppress our unused vars lint rule. const { buttonProps, otherProps } = useSomeReactAria();
const {
//eslint-ignore unused
nonHtmlProp,
//eslint-ignore unused
otherNonHtmlProp,
...safeButtonProps
} = buttonProps;
/* ... */
return <button {...safeButtonProps} />I've seen other teams with similar setups to ours, but not many - the most notable example being Sentry which uses emotion rather than native HTML and that affords them a prop filter out of the box. If there's a better solution that I just haven't been able to find, bully! Otherwise, I'd say that internal use is a decent indicator that at least teams who use react-aria directly against native HTML (definitely my team 😁) would find this a useful feature? |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
-
This is more of a question regarding best practices and patterns. As we build out our internal design system, we have regularely referenced React Spectrum and
react-aria-componentssource code. We have seen the usage of a utilityfilterDOMPropsbut there really is not much info on this. I am mainly curious what the best practices around this are, and what this utility accomplishes in a Typescript world.My first impression is that it is filtering out props from within the component, so what role does this play if our users are using Typescript exclusively?
It seems to me that this utility is mostly a fallback to ensure that random props do not leak to the DOM in a Non-Typescript environment, would that be a good assumption?
It seems like
filterDOMPropsdoes not also include props likestyleandclassName, so would the idea be that those DOM props always get manually added to our types and de-structured out?Beta Was this translation helpful? Give feedback.
All reactions