2017-06-19 22 views
0

This is the button where i called the handleClick function. I think the onClick event isn't working properly (only works if i equal it to console.log('button clicked) which logs the string to the console.)未捕获的错误:预期的onClick监听器是一个函数,而不是得到了字符串类型

This is the handleClick() function which passes the value to the property of the component.

我不知道为什么它不工作。以前,onClick自动启动,但现在它没有这个问题。 P:我尝试了一个IIFE int onCLick事件,它仍然将消息记录到控制台,但它似乎不适用于handleClick()

在此先感谢。 :)

+3

任何机会你可以张贴代码本身,而不是图像..? –

+1

如果可以的话,请发布这个完整的组件...这将是非常有用的搞清楚什么'this.props.onClick()'应该做的... – OneNeptune

+0

@KarlReid实际上它是一个非常长的代码,所以它没有无法发布整个代码。 –

回答

1

试着这么做:

handleClick:function(){ 
    return(this.props.onClick('app/src/wallpaperModule/3.jpeg')) 
} 
+0

函数stil不起作用。我在'handleClick()'(在return语句之前)里放了一个'console.log()',但是在点击按钮之后控制台上什么也没有。 –

+0

它似乎'onClick'不能运行该功能。 –

+0

@RishiKumar请发布您的代码,以便我可以更好地为您提供帮助。另外,如果不提供参数,'console.log()'不会在控制台中放置任何东西。试着把'console.log(this.props)'放在你的Component构造函数中。 – OneNeptune

相关问题