in React JS by
Q:

How to conditionally apply class attributes?

1 Answer

0 votes
by

You shouldn't use curly braces inside quotes because it is going to be evaluated as a string.

<div className="btn-panel {this.props.visible ? 'show' : 'hidden'}">

Instead you need to move curly braces outside (don't forget to include spaces between class names):

<div className={'btn-panel ' + (this.props.visible ? 'show' : 'hidden')}>

Template strings will also work:

<div className={`btn-panel ${this.props.visible ? 'show' : 'hidden'}`}>
Click here to read more about React JS
Click here to read more about Insurance

Related questions

0 votes
asked Mar 2, 2020 in React JS by RShastri
+1 vote
asked Jul 31, 2020 in Matlab by sharadyadav1986
0 votes
asked Jan 30 in React JS by rajeshsharma
0 votes
asked Aug 13, 2020 in XML by SakshiSharma
+1 vote
asked Feb 3, 2020 in Data Handling by MBarbieri
...