I have React component, with state managed by redux, ul list and a css-class. I want to apply class to one of li elements, depending on state. For instance, if myStateProp = a, apply css class to first li, if myStateProp = b, apply class to second li and so on. But I'm not sure how to do it properly.
For now I solved this problem like this:
<ul>
<li className={this.props.myStateProp ==="a" ? "myCssClass" : ""}>A</li>
<li className={this.props.myStateProp ==="b" ? "myCssClass" : ""}>B</li>
<li className={this.props.myStateProp ==="c" ? "myCssClass" : ""}>C</li>
</ul>
But I don’t really like this approach, seems too many copied code. Maybe there is a way to do it more neatly?
handleClick(e)function which will assign the class one.target. It's really hard to tell without proper context.