Search code examples
javascriptreactjsternary-operatoror-operator

Ternary operator with "OR" operator not working?


 {this.state.accordian === "Updated Port Entry" || "Updated Shipper Updates" ||  "Updated MT Container Details" ? 

    <li className="remove">
            <a role="button" className="boxs-close" onClick={this.Depottoggle.bind(this)}><i className="zmdi zmdi-plus collapseColor"></i></a>
    </li> : null}

In the state this.state.accordian having "Updated Truck Details". As I am checking based on a) Updated Port Entry b) Updated Shipper Updates c) Updated MT Container Details

as It is not matched It should not be shown but I am able to see the Icon.

Please guide me.


Solution

  • You need to use this.state.accordian each time you compare it.

    this.state.accordian === "Updated Port Entry" || this.state.accordian === "Updated Shipper Updates" || this.state.accordian === "Updated MT Container Details"