简体   繁体   中英

how to use and in the properties section of the html element in react?

I had a situation like if 1st name exists in the obj , I need to do some more styling to that div so I am thinking like using and operator in react like this , if name exists add id to the div , but it is showing error

<div {obj["name"][0] && id="feature-border"} className="rectangle"> </div>

can anyone help me , how to use and in the properties section of the html element in react ??

<div {obj["name"][0] && id="feature-border"} className="rectangle"> </div>

Change this line of code to,

<div id={obj["name"][0] ? "feature-border" : ""} className="rectangle"> </div>

Or

<div id={obj["name"][0] ? "feature-border" : null} className="rectangle"> </div>

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