简体   繁体   中英

Create class in ReactJs using JSX

I want to create class in React using JSX. I have a dashboard built on react. I selected a part and through inspect element (Google developer console) I got the react id. Now, I want to create a class using JSX, like class=newclass . I have plan to use it in further CSS. I can insert manually from template. But, I want to do it through JSX, also want to test from console temporarily by running the code fron console. This is present area :-

 <label data-reactid=".0.b.1.0.1.1.0.0.0.0.0.0">This is text</label> 

and I want to add a class there using JSX,

 <label data-reactid=".0.b.1.0.1.1.0.0.0.0.0.0" class="newclass">This is text</label> 

尝试这个:

<label className='newclass'>This is text</label>

JSX tags and attributes may differ from HTML ones. Please view the following resource: https://facebook.github.io/react/docs/tags-and-attributes.html

Indeed, a class in JSX is created via the "className" attribute instead of "class". To place the class on the element you can simply do:

<label data-reactid=".0.b.1.0.1.1.0.0.0.0.0.0" className="newclass">This is text</label>

To insert a dynamic class you should use something like the following syntax :

var newclass = this.props.newclass; return ( <label data-reactid=".0.b.1.0.1.1.0.0.0.0.0.0" className={newclass}>This is text</label> );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM