mumuhou mumuhou - 26 days ago 8
React JSX Question

parse error handleDismissClick = e =>


SyntaxError: /Users/mumuhou/github/web/react/examples/basic-commonjs/index.js: Unexpected token (7:21) while parsing file: /Users/mumuhou/github/web/react/examples/basic-commonjs/index.js


My code:

'use strict';

import React, { Component, PropTypes } from 'react'
import ReactDOM from 'react-dom'

class App extends Component {
handleDismissClick = e => {
e.preventDefault()
}

render() {
var elapsed = Math.round(this.props.elapsed / 100);
var seconds = elapsed / 10 + (elapsed % 10 ? '' : '.0' );
var message =
'React has been successfully running for ' + seconds + ' seconds.';

return <p>{message}</p>;
}
}

var start = new Date().getTime();

setInterval(function() {
ReactDOM.render(
<App elapsed={new Date().getTime() - start} />,
document.getElementById('container')
);
}, 200);


I have config es2015

Answer
class App extends Component {
  handleDismissClick = e => {
    e.preventDefault()
  }
}

is the public class fields proposal. In order for Babel to understand and convert it, you have to load the corresponding plugin, or simply use the stage-2 preset.