True custom attributes (e.g. Microdata) in React

Chris Pearce picture Chris Pearce · Feb 8, 2014 · Viewed 13.2k times · Source

The site I am developing makes use of Microdata (using schema.org). As we are shifting development over to use React to render our views I have hit a blocker where React will only render attributes in the HTML spec however Microdata specifies custom attributes such as itemscope.

As I'm relatively new to React and haven't had chance to fully understand the core just yet, my question is what would be the best way to extend the functionality of react.js to allow for defined custom attributes, e.g., Microdata?

Is there a way of extending the attributes/props parser or is it a job for a mixin which checks all passed props and modifies the DOM element directly?

(Hopefully we'll be able to put together a drop in extension for everyone to provide support for this when a solution is clear.)

Answer

Christian Steinmann picture Christian Steinmann · Nov 22, 2015

You can also use "is" attribute. It will disable the attribute white-list of React and allow every attribute. But you have to write class instead of className and for instead of htmlFor if you use is.

<div is my-custom-attribute="here" class="instead-of-className"></div>

Update React 16 custom attributes are now possible

In react 16 custom attributes are now possible

React 16 custom attributes