4 ms·
This is interesting > Instead of ignoring unrecognized HTML and SVG attributes, React will now pass them through to the DOM. Does that mean we can start using
by scottfr 9y ago
This is interesting
> Instead of ignoring unrecognized HTML and SVG attributes, React will now pass them through to the DOM.
Does that mean we can start using "class" instead of "className"?
- syntor 9y agoI always assumed `class` was a keyword, which is why then went with `className` instead.
- sorahn 9y agoboth `className` and `htmlFor` are what the actual DOM uses. [1][2] [1]: https://developer.mozilla.org/en-US/docs/Web/API/Element/className https://developer.mozilla.org/en-US/docs/Web/API/Element/cla... [2]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/htmlFor https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelEl...
- danabramov 9y agoYes, the reason is that you can't write something like const { class } = props Which is very common and deeply confusing. So even though "class" will technically work now, it will still warn, and ask that you use "className". (And officially supporting both would make it confusing for third party components since each would have to also support both.)
- iBelieve 9y agoI think you can (with a warning), but it's still recommended to use the normal React naming conventions according to [0]: > Note: always use the canonical React naming for all supported attributes. Looking through the examples, it looks like non-string class values will be converted to strings, while non-string className values will be ignored (with a warning). [0] https://facebook.github.io/react/blog/2017/09/08/dom-attributes-in-react-16.html https://facebook.github.io/react/blog/2017/09/08/dom-attribu...