Skip to content

arrow function is not supported #117

@wulucxy

Description

@wulucxy
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 = () => {
                   ^

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions