I want to write the equivalent in react:
if (this.props.conditionA) {
Condition A
} else if (this.props.conditionB) {
If you don't need the You can even move the last In general, you don't have to embed everything inside JSX. It's perfectly fine to compute values beforehand, just like you do elsewhere: You have to do that whenever you need / want to use a statement. elements:
render() {
if (this.props.conditionA) {
return Condition A;
} else if (this.props.conditionB) {
return Condition B;
} else {
return Neither;
}
}
return statement out of the else block.
render() {
let content;
if (this.props.conditionA) {
content = Condition A;
} else if (this.props.conditionB) {
content = Condition B;
} else {
content = Neither;
}
return