ternary operator in jsx to include html with react

前端 未结 6 1828
离开以前
离开以前 2020-12-23 11:12

I\'m using react and I\'m trying to display this error message if this.state.message === \'failed\'. But I\'m really not sure why this ternary operation isn\'t

6条回答
  •  庸人自扰
    2020-12-23 12:01

    Given the above answers, you can also directly return a ternary expression from return() in your render() like this

    return condition? this.function1(): this.function2();
    

    and inside function1() and function2() you can return your views.

提交回复
热议问题