I'm learning react and trying to add a class if a select element holds a value that I want to check against.
class App extends Component {
test = 'volvo';
render() {
return (
<select style={{marginTop: '30px', marginLeft: '20px'}}>
<option value="volvo" className={test === 'volvo' ? "selected" : null}>Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
);
}
}
It's giving me an error where on the line here I have the ternary operator. Can someone tell me the proper way of doing this please? Thanks!