【问题标题】:Call component from onClick function in react js从反应js中的onClick函数调用组件
【发布时间】:2021-11-24 11:21:58
【问题描述】:

我想编辑用户详细信息,所以我有

 <button onClick={() => this.edit(n.id)}>Edit</button>

edit = (id) => { 
     <Editbranches/>
  }

这里的 Editbranches 是另一个组件。如何在用户函数中调用组件?请帮助

【问题讨论】:

  • 调用组件?你想渲染它吗?

标签: reactjs function popup


【解决方案1】:

如果您打算渲染 Editbranches 那么:


  <button onClick={() => this.setState({ edit: n.id })}>Edit</button>

 {
     this.state.edit && <Editbranches/> 
 }

【讨论】:

    猜你喜欢
    • 2016-04-03
    • 1970-01-01
    • 2023-01-29
    • 2018-08-20
    • 1970-01-01
    • 1970-01-01
    • 2020-03-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多