-
Notifications
You must be signed in to change notification settings - Fork 257
Closed
Description
const componentClassExample = `
class Counter extends React.Component {
constructor() {
super()
this.state = { count: 0 }
}
componentDidMount() {
this.interval = setInterval(() => {
this.setState(state => ({ count: state.count + 1 }))
}, 1000)
}
// it will throw an error out:
// SyntaxError: Unexpected token (13:14)
handleClick = () => {
}
componentWillUnmount() {
clearInterval(this.interval)
}
render() {
return (
<center>
<h3>
{this.state.count}
</h3>
<button onClick={this.handleClick}>按钮</button>
</center>
)
}
}
`.trim();this.handleClick will throw an error out:
SyntaxError: Unexpected token (13:14)
9 : this.setState(state => ({ count: state.count + 1 }))
10 : }, 1000)
11 : }
12 :
13 : handleClick = () => {
^Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels