teatime-components icon indicating copy to clipboard operation
teatime-components copied to clipboard

Remove 'unkown props' from DOM elements; fixes #16

Open ojame opened this issue 8 years ago • 1 comments

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 consts and would just get pretty messy.

Let me know your thoughts!

ojame avatar Jul 13 '16 01:07 ojame

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

mightyaleksey avatar Jul 13 '16 10:07 mightyaleksey