I'm new to React and struggling with the syntax. I have this block as a div inside my render function. Every change I make goes from one syntax error or another or just doesn't work.
<div className="skillSection">
{
if (this.state.challengeChoices.length < 0) {
this.state.challengeChoices.map((para2, i) =>
<ChallengeSkill key={i} {...para2} callback={this.madeSelection} />)
}
else {
return <div>Hello world</div>
}
}
</div>
jsx doesn't support
conditional statement
, but it supportternary operator
, so you can do it like this:I like the following approach when it's just an
if
statement:Of course, if/else has many options:
Recommend making a function: