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