React中的奇怪语法错误

时间:2017-10-20 06:18:13

标签: javascript reactjs babeljs unexpected-token

所以我有class App的自定义组件,但仍有问题。我确定它很简单,但对于我这样的人来说,我并不是想弄清楚它。基本上,我的代码是:

(app.jsx):

import React from 'react';
import '../styles/index.scss';

const EventCalendar = require('react-event-calendar');

const events = [
    {
        start: '2015-07-20',
        end: '2015-07-02',
        eventClasses: 'optionalEvent',
        title: 'test event',
        description: 'This is a test description of an event',
    },
    {
        start: '2015-07-19',
        end: '2015-07-25',
        title: 'test event',
        description: 'This is a test description of an event',
        data: 'you can add what ever random data you may want to use later',
    },
];

export default class App extends React.Component {
  render() {
    return (
      <div>
        <h1>It Works!</h1>
        <p>This React project just works including <span className="redBg">module</span> local styles.</p>
        <p>Enjoy!</p>

                <EventCalendar
                    month={7}
                    year={2017}
                    events={events}
                    onEventClick={(target, eventData, day)} => console.log(eventData)
                    />

      </div>
    )
  }
}

当我跑步时,我收到了这个错误:

enter image description here

有人可以协助吗?

非常感谢。

更新:我修复了建议的语法错误,因为我正在尝试使用它来学习一些新的反应,我正在使用this project的示例项目,但现在得到这个如屏幕截图所示:< / p>

enter image description here

1 个答案:

答案 0 :(得分:1)

Webpack构建错误有时可能很微妙:

import React from 'react';
import '../styles/index.scss';

const EventCalendar = require('react-event-calendar');

const events = [
    {
        start: '2015-07-20',
        end: '2015-07-02',
        eventClasses: 'optionalEvent',
        title: 'test event',
        description: 'This is a test description of an event',
    },
    {
        start: '2015-07-19',
        end: '2015-07-25',
        title: 'test event',
        description: 'This is a test description of an event',
        data: 'you can add what ever random data you may want to use later',
    },
];

export default class App extends React.Component {
  render() {
    return (
      <div>
        <h1>It Works!</h1>
        <p>This React project just works including <span className="redBg">module</span> local styles.</p>
        <p>Enjoy!</p>

                <EventCalendar
                    month={7}
                    year={2017}
                    events={events}
                    onEventClick={(target, eventData, day) => console.log(eventData)} // the closing curly brace
                    />

      </div>
    )
  }
}