How can I write an else if structure using React (JSX) - the ternary is not expressive enough

前端 未结 6 1669
情话喂你
情话喂你 2021-01-01 18:47

I want to write the equivalent in react:

if (this.props.conditionA) {
    Condition A
} else if (this.props.conditionB) {
    

        
6条回答
  •  清酒与你
    2021-01-01 19:33

    Indeed, that is not the way.

    var element;
    if (this.props.conditionA) {
        element = (Condition A)
    } else if (this.props.conditionB) {
        element = (Condition B)
    } else {
        element = (Neither)
    } 
    ...
        {element}
    

提交回复
热议问题