teatime-components
teatime-components copied to clipboard
Remove 'unkown props' from DOM elements; fixes #16
This is an interesting problem to 'solve', this was the cleanest and most transparent method I could think of. It touches a bunch of files, though.
Another option was just to const {invalidProps, ...everythingElse} = this.props
and then <span ...everythingElse>
in a one liner. But it would produce a lot of unused const
s and would just get pretty messy.
Let me know your thoughts!
Hi, thank you for your interest!
Actually, I was going to replace mixin/StyleComponent.js with simple inheritance first and think about this issue after.
As far as I know there are two opportunities to solve it: use the white list and provide only necessary props to the React.createElement
or use the black list and omit unnecessary props.
Mostly that issue appear from using custom props styles
and styleName
and other props that come from the components
level (theme
, size
and etc). And in the simple cases we can manually set the unwanted properties to undefined
: https://babeljs.io/repl/#?evaluate=true&lineWrap=false&presets=es2015%2Creact%2Cstage-2&code=function%20Link(props)%20%7B%0A%20%20return%20(%0A%20%20%20%20%3Ca%20%7B...props%7D%20className%3D%7BstyleName(props)%7D%20styleName%3D%7Bundefined%7D%20styles%3D%7Bundefined%7D%2F%3E%0A%20%20)%3B%0A%7D (that avoids necessity for another iteration and object creation).
But I'm not sure what's better to use for the other cases.
I'll try to review yours pr at the weekend and may be I'll come with a more thoughtful answer. Thanks