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.
I am expecting more interesting topics from you. And this was nice content and definitely it will be useful for many people.
ReplyDeleteiOS App Development Company
Android App Development Company
Mobile App Development Company