ternary operator in jsx to include html with react

前端 未结 6 1830
离开以前
离开以前 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:11

    For using variable inside ternary use brackets again

    render() {
      return(
        
    {this.state.var ?
    {this.state.var}
    : ''}
    ) }

提交回复
热议问题