简体   繁体   English

预期 onClick 事件侦听器是函数但有对象类型 - ReactJS

[英]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.

相关问题 ReactJS:预期 onClick 侦听器是一个函数,而不是类型字符串 - ReactJS: Expected onClick listener to be a function, instead got type string 错误:期望onClick侦听器是一个函数,而是使用reactjs获得类型对象 - Error: Expected onClick listener to be a function, instead got type object using reactjs 未捕获的错误:预期的“onClick”侦听器是 function,而不是“object”类型的值。 ReactJS - Uncaught Error: Expected `onClick` listener to be a function, instead got a value of `object` type. ReactJS 错误:预期 `onClick` 侦听器是一个函数,而不是 `object` 类型的值 - Error: Expected `onClick` listener to be a function, instead got a value of `object` type 预期 onClick 侦听器是 function,而不是类型 object - 反应 Z7490FE17CAE6208E8B - Expected onClick listener to be a function, instead got type object - react redux 期望onClick侦听器是一个函数,而是使用类型字符串Unknown事件处理程序属性onclick。 您是说“ onClick”吗? - Expected onClick listener to be a function, instead got type string Unknown event handler property onclick. Did you mean `onClick`? React-Redux 操作 - 预期 `onClick` 侦听器是 function 而不是 `object` 类型的值 - React-Redux action - Expected `onClick` listener to be a function instead got a value of `object` type 警告:预期的“onClick”侦听器是 function,而不是“object”类型的值。 -反应 - Warning: Expected `onClick` listener to be a function, instead got a value of `object` type. -react 未捕获的不变违规:预期onClick侦听器是一个函数,而是获得类型对象 - Uncaught Invariant Violation: Expected onClick listener to be a function, instead got type object 预期onClick侦听器是一个函数,而取值为string类型 - Expected `onClick` listener to be a function, instead got a value of `string` type
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM