简体   繁体   English

将道具传递给 onClick function 得到错误 function 得到值字符串

[英]pass props to onClick function getting error function got value string

I'm trying to pass a props to other file and active some function in there我正在尝试将道具传递给其他文件并在其中激活一些 function

<CustomHtml NameF="Print"/>

this is in App.js这是在 App.js 中

if we go to CustomHtml Function!如果我们 go 到 CustomHtml 函数!

function CustomHtml({NameF}){
  
 function Print(){
 consol.log("Hi)
 }

    return(

        <button onClick={NameF}>Click Me<button />
      )
    } 
  export default CustomHtml 

and then i got this error saying " onClick listener to be a function, instead got a value of string type. "然后我收到此错误消息“ onClick侦听器是 function,而不是string类型的值。”

Error is valid you are passing "Print" string as prop.错误是有效的,您将"Print"字符串作为道具传递。 If you want to pass Print function as callback, you should change the component as如果您想通过Print function 作为回调,您应该将组件更改为

<CustomHtml NameF={Print}/>

Also, Print function should be accessible in the component where CustomHtml component is used.此外,在使用CustomHtml组件的组件中应该可以访问Print function。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 收到此错误…invariant.js:42未捕获的错误:预期onClick侦听器是一个函数,而是得到了string类型的值 - Getting this error… invariant.js:42 Uncaught Error: Expected `onClick` listener to be a function, instead got a value of `string` type 道具不传递给onClick函数 - Props not getting passed to onClick function 已更新至Chrome v65并开始出现此错误:预期onClick侦听器是一个函数,而不是类型字符串 - Updated to Chrome v65 and started getting this error: Expected onClick listener to be a function, instead got type string 未捕获的错误:预期的“onClick”侦听器是 function,而不是“字符串”类型的值 - Uncaught Error: Expected `onClick` listener to be a function, instead got a value of `string` type 警告:预期的“onClick”侦听器是 function,而不是“字符串”类型的值 - Warning: Expected `onClick` listener to be a function, instead got a value of `string` type 如何在相同的onclick上传递道具并激活功能? - How to pass props and activate function on same onclick? 将 onClick function 作为道具传递给子组件 - pass onClick function as a props to sub component 预期onClick侦听器是一个函数,而取值为string类型 - Expected `onClick` listener to be a function, instead got a value of `string` type 错误:预期 `onClick` 侦听器是一个函数,而不是 `object` 类型的值 - Error: Expected `onClick` listener to be a function, instead got a value of `object` type 我将一个函数从父级传递给子级,在子级onClick上实现了该函数。 出现错误:this.props.function()不是函数 - I passed a function from parent to child, implemented it onClick on the child. Getting Error: this.props.function() is not a function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM