How to add a style to a React Element if it is created in this way?

var MyElement = React.createClass({displayName: "FormatParagraph", render: function () { return ( React.createElement("p", null, this.props.paragraph) ); } }); 

How to add a style object to this?

+16
source share
2 answers

The second parameter, createElement is an attribute hash, where key is the attribute name and value is the attribute value. The style attribute accepts hash values ​​for style names. So for example:

 React.createElement("p", {style: {color: "red", backgroundColor: "blue"}}, this.props.paragraph) 
+24
source
 React.createElement("p", {id : 'div1', className : 'news'}, this.props.paragraph) 

This way you can use the CSS specified in App.css inside id/class .

0
source

Source: https://habr.com/ru/post/987354/


All Articles