The code does the following - if the item selected from the dropdown menu is 'pinpong' then it will show the content within the div container content
In the second component if the item selected from the dropdown menu is 'basketball' it will also then show the div container content.
However, the content to be shown is the same. So is there a way to combine the component to be rendered
with a logical operator ||
that will eliminate the need to be so repetitive with the code?
{this.props.selectedGame === 'pingpong' && (
<div>
<label>
<p>How many games do you want to play?</p>
<input onChange={this.handleChangeInput}
type="text"/>
</label>
</div>
)}
{this.props.selectedGame === 'basketball' && (
<div>
<label>
<p>How many games do you want to play?</p>
<input onChange={this.handleChangeInput}
type="text"/>
</label>
</div>
)}
What I often do in these cases where the condition for rendering gets rather long is create a function that will handle the condition and return a boolean