Reactjs 不显示返回

Reactjs 不显示返回,reactjs,Reactjs,我有一个三元运算符和if-else语句,但三元运算符不返回任何内容。控制台上没有错误,因此我假设它已成功运行 renderTags() { this.state.tags.length === 0 ? ( <h3>There are no tags!</h3> ) : ( <ul> {this.state.tags.map((tag) => ( <li key={tag}&

我有一个三元运算符和if-else语句,但三元运算符不返回任何内容。控制台上没有错误,因此我假设它已成功运行

renderTags() {
    this.state.tags.length === 0 ? (
      <h3>There are no tags!</h3>
    ) : (
      <ul>
        {this.state.tags.map((tag) => (
          <li key={tag}>{tag}</li>
        ))}
      </ul>
    );
    if (this.state.tags.length === 0) {
      <h3>There are no tags!</h3>;
    }
    return (
      <ul>
        {this.state.tags.map((tag) => (
          <li key={tag}>{tag}</li>
        ))}
      </ul>
    );
  }

您使用的是三元运算符,但没有对其结果进行任何处理(这就是为什么控制台没有显示任何错误)。应该是:

renderTags() {
    return this.state.tags.length === 0 ? (
      <h3>There are no tags!</h3>
    ) : (
      <ul>
        {this.state.tags.map((tag) => (
          <li key={tag}>{tag}</li>
        ))}
      </ul>
    );
  }
renderTags(){
返回this.state.tags.length==0(
没有标签!
) : (
    {this.state.tags.map((tag)=>(
  • {tag}
  • ))}
); }
renderTags() {
    return this.state.tags.length === 0 ? (
      <h3>There are no tags!</h3>
    ) : (
      <ul>
        {this.state.tags.map((tag) => (
          <li key={tag}>{tag}</li>
        ))}
      </ul>
    );
  }