You get a bonus - 1 coin for daily activity. Now you have 1 coin

How do you conditionally apply class attributes? in REACT

Practice



You must not use curly braces inside quotes, because they will be evaluated as a string.

<div className="btn-panel {this.props.visible ? 'show' : 'hidden'}">
 
Instead, you need to move the curly braces outside (and don't forget to include the spaces between class names):
< div  className = { ' btn-panel '  + ( this . props . visible  ?  ' show '  :  ' hidden ' ) } >

Template strings will also work:

  1. <div className={`btn-panel ${this.props.visible ? 'show' : 'hidden'}`}>
  2.  

Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Scripting client side JavaScript, jqvery, BackBone"

Terms: Scripting client side JavaScript, jqvery, BackBone