ReactJS 需要根据逻辑有条件地显示不同的 onclick vs Link

ReactJS need to conditionally display different onclick vs Link based on logic

我的目标是显示不同的 HTML onclick 与 route

Render() 中没有逻辑const contents = this.state.data.map(item => (

这就是我纠结的逻辑

<button id={item.Member_ID} type="button"
  {` ${this.isExist(item.Member_ID) ? <Link to='surveysai/'>
      <button type="button" className='btn btn-success'>SAI</button>  </Link>             
    : ${onClick={(e) => this.downloadUser(item.Member_ID, e)}}`}
    className={`btn ${this.isExist(item.Member_ID) ? "btn-success" : "btn-warning"}`} > {this.isExist(item.Member_ID) ? "SAI" : "Ready for Download"}</button>

这来自按钮 class:

<button id={item.Member_ID} type="button"
 className={`btn ${this.isExist(item.Member_ID) ? "btn-success" : "btn-warning"}`} > {this.isExist(item.Member_ID) ? "SAI" : "Ready for Download"}</button>   

以下是更改为条件之前的旧代码,以下不是我想要的代码,仅供参考。

点击

<button id={item.Member_ID} type="button" onClick={(e) => this.downloadUser(item.Member_ID,e)} 
      className={() => this.checkItem(item.Member_ID)}>Ready for Download</button>

Link 路由重定向

<Link to='surveysai/'>
    <button type="button" className="btn btn-success">SAI</button>                   
</Link>

为什么不有条件地呈现 Link 或按钮。

{this.isExist(item.Member_ID) ? (
  <Link to='surveysai/'>
      <button type="button" className='btn btn-success'>SAI</button>  
  </Link>
) : (
  <button 
    onClick={(e) => this.downloadUser(item.Member_ID, e)}
    className={`btn ${this.isExist(item.Member_ID) ? "btn-success" : "btn-warning"}`}> {this.isExist(item.Member_ID) ? "SAI" : "Ready for Download"} . 
  </button>
)}

此外,假设这是一个 React Router Link 组件,您实际上不需要在 Link 内呈现按钮。您可以将类名作为道具传递,例如:

<Link to="/wherever" className="btn btn-success" />