[英]event not firing on react component using arrow function
import React, { Component } from 'react'
import { connect } from 'react-redux'
@connect(
state=>state.user
)
class Profile extends Component {
logout(){
alert('logout')
}
render() {
const props = this.props
return props.user && (
<div>
<button onClick={()=>{this.logout()}}>Logout</button>
</div>
)
}
}
export default Profile 导出默认配置文件
I click on the button, the alert is not triggered, no error no warning now I'm lost. 我单击按钮,警报没有触发,没有错误,没有警告,现在我迷路了。 What can be the possible cause? 可能是什么原因?
I tried below code and everything seems fine. 我尝试下面的代码,一切似乎都很好。 May be your this.props is not having any value. 可能是您的this.props没有任何价值。 Can you share that code as well. 您是否也可以共享该代码。 I see everything is fine in component. 我看到组件中的一切都很好。
class Hello extends React.Component { 类Hello扩展了React.Component {
logout(){
alert('logout')
}
render() {
return (
<div>
<button onClick={()=>{this.logout()}}>Logout</button>
</div>
)
}
} }
ReactDOM.render( , document ReactDOM.render(,文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.