[英]Expected onClick event listener to be function but got object type - ReactJS
I get expected onClick
event listener to be a function but got object type error.我期望
onClick
事件侦听器是一个函数,但得到了对象类型错误。 Can someone help me to solve this problem?有人可以帮我解决这个问题吗?
Below is my code snippet:下面是我的代码片段:
render_detail_options = () => {
return(
<div>
<component-name
name={detail.name}
recipient={detail.recipient}
/>
</div>
);
};
render = () => {
return (
<div className="details">
<table>
<thead>
<tr>
<th>...</th>
</tr>
</thead>
<tbody>
{this.state.details.map((detail) => {
const option = this.props.options.find(option => option.id === detail.option_id);
return (
<tr key={detail.id}>
<td>{detail.recipient}</td>
<td>
<some-component>
<button>...</button>
<span onClick={this.render_detail_options(share, model)}>Edit</span>
</some-component>
</td>
</tr>
</tbody>);
<span onClick={this.render_detail_options(share, model)}>Edit</span>
try here with ES6 arrow function: 在这里尝试使用ES6箭头功能:
onClick={(e) => this.handleClick(param, e)} onClick = {(e)=> this.handleClick(param,e)}
Try refactoring it like this, and let me know if it solved your issue. 尝试像这样重构它,并让我知道它是否解决了您的问题。
<some-component>
<button onClick={() => this.render_detail_options(data)}>Edit</button>
</some-component>
I would also suggest visiting these docs . 我也建议访问这些文档 。 They have everything you need.
他们拥有您需要的一切。
You are not giving the onClick a call back. 您没有给onClick回电。 Try
onClick={()=> this.render_detail_options(share, model)}.
尝试
onClick={()=> this.render_detail_options(share, model)}.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.