styled-components: v4 passes through unknown HTML attribute to the DOM
Environment
npm packages:
- react: v16.5.2
- react-dom: v16.5.2
- styled-components: v4.0.2
Reproduction
https://codesandbox.io/s/zn5vrk0vpm
Expected Behavior
https://codesandbox.io/s/20xlp242pr
There is no unknown-prop warning if I’m using styled(styled.button).attrs({ customProp }) with styled-components v3.4.10.
Actual Behavior
There is unknown-prop warning with styled-components v4.

If this is not a bug, and there is something missing. Please let me know, thanks!
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 3
- Comments: 17 (8 by maintainers)
Will this be resolved in v5 for the
Link(or any other custom components)?I’m seeing a similar issue with the new
asprop, e.g.:Is this related to an existing issue or should I open a new issue?
As a workaround for eliminating React warnings in custom components, I had to make use of
data-*attributes.Fixed in #2133 However, pay attention to #2093. It will add new way to tell which attributes should pass as html attributes
The top answer here solved it for me
This isn’t a bug, we explicitly do not filter props for custom components because we don’t know if the component needs to consume the prop as well.
Sent from my iPhone
Seeing as this still happens in v5 for custom components, can we reopen this issue? Or create a new one?
Is there any ETA on when this can be addressed? Or let me know if I can help with the PR and what the challenge is.