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

前端 未结 6 1696
情话喂你
情话喂你 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条回答
  •  梦毁少年i
    2021-01-01 19:26

    Why do you say that the ternary is not expressive enough?

    render() {
      return 
        {this.props.conditionA ? "Condition A" 
          : this.props.conditionB ? "Condition B" 
          : "Neither"}
      ;
    }
    

提交回复
热议问题