【发布时间】:2021-10-23 19:24:34
【问题描述】:
我正在尝试使用按钮显示每次点击的计数,但我的代码遇到了问题。当我运行我的代码时,它无法编译,但是当您检查页面时,您可以看到正在显示的时间。这是我的代码。
import React from 'react'
export default class Profile extends React.Component{
constructor(){
super();
this.state={
name:'Abdur Rehman',
email: 'abdur@gmail.com',
count: 0,
}
}
test(){
this.setState({
name: 'Jamal',
email: 'jamal123@gmail.com',
count: count+1
}
)
}
render(){
return(
<div>
<h1>hello {this.state.name}</h1>
<h1>Email: {this.state.email}</h1>
<h1>Count: {this.state.count}</h1>
<button onClick={()=>{this.test()}}>Update Name</button>
</div>
);
}
}
【问题讨论】:
标签: javascript compiler-errors compilation