您的位置:首页 > Web前端 > React

React学习笔记(六)事件处理

2018-01-24 11:12 585 查看
//事件处理
class Toggle extends React.Component{
constructor(props){
super(props);
this.state = {isToggleOn:true};
this.handleClick = this.handleClick.bind(this)
}
handleClick(){
this.setState(prevState => ({
isToggleOn: !prevState.isToggleOn
}))
}
render(){
return(
<button onClick={this.handleClick}>
{this.state.isToggleOn ? 'on':'off'}
</button>
)
}
}
ReactDOM.render(
<Toggle/>,
document.getElementById('button')
)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: