javascript - How to enact styles with React.js -


i trying use inline styles react.js, keep running errors:

in render function, have:

render: function() {     var style = this.state.submitted ? {{"backgroundcolor": "#1abc9c", "opacity": "0.6"}} : {{}};      return (       <div>          <h1 classname="home-two-question" style={style}>{text}</h1>        </div>     )   }, 

basically want toggle style on click. however, when run this, error react.js. correct syntax inline styles in react.js? thank you!

in line:

var style = this.state.submitted ? {{"backgroundcolor": "#1abc9c", "opacity": "0.6"}} : {{}}; 

you're in plain javascript, not inside of jsx tag. thus, want use single {}, not double {{}}:

var style = this.state.submitted ? {"backgroundcolor": "#1abc9c", "opacity": "0.6"} : {}; 

in particular, when like:

<div style={{"backgroundcolor": "white"}}> 

there 1 set of {} denote value of style prop should interpreted javascript, , set of {} denote constructing object within value.


Comments

  1. I am expecting more interesting topics from you. And this was nice content and definitely it will be useful for many people.
    iOS App Development Company
    Android App Development Company
    Mobile App Development Company

    ReplyDelete

Post a Comment

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -