Using OR in ternary operator

RCo*_*hen 3 javascript reactjs

I have a simple ternary operator, where I want to return null with two different strings.

this.props.sportType === 'tennis' || 'soccer' ? null : <li onClick={this.props.onClick} className={styles.menuItem}>N/A</li>
Run Code Online (Sandbox Code Playgroud)

不幸的是,但这并不完全有效。我如何使用|| 正确地使用三元运算符?

谢谢!:)

Cer*_*nce 5

使用数组,查看是否sportType包含在数组中:

['tennis', 'soccer'].includes(this.props.sportType)
? null
: <li onClick={this.props.onClick} className={styles.menuItem}>Sport</li>
Run Code Online (Sandbox Code Playgroud)

(也最好缩进较长的表达式)


Nin*_*olz 5

用第二个值重复比较

this.props.sportType === 'tennis' || this.props.sportType === 'soccer'
    ? ...
Run Code Online (Sandbox Code Playgroud)