Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Non standard custom attributes in ReactJS?

Tags:

reactjs

This is regarding non-standard attributes. https://facebook.github.io/react/docs/tags-and-attributes.html

In react I have done this:

 React.createElement('div', {image:'blah', etc:'blah'});

I need image and etc to be set on the element with setAttribute, and I need react to use its smarts to maintain it as it changes.

A solution here https://stackoverflow.com/a/21654914/1828637 says to add it on componentDidMount but this is not a solution. The attribute will not be maintained as it changes by the react framework.

Is there anyway to tell react to set the attribute on my custom tags?

like image 986
Noitidart Avatar asked Apr 08 '26 05:04

Noitidart


1 Answers

In react 16 custom attributes are now possible

// Your code:
<div mycustomattribute="something" />

// React 15 output:
<div /> 

// React 16 output:
<div mycustomattribute="something" />

react 16 custom attributes

like image 76
Morris S Avatar answered Apr 09 '26 20:04

Morris S