0

所以我有自定义组件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>
    )
  }
}

但是,当我运行时,出现此错误:

在此处输入图像描述

有人可以帮忙吗?

非常感谢。

更新:我按照建议修复了语法错误,当我试图用它来学习反应中的新东西时,我正在使用这个项目的示例项目,但现在得到这个,如屏幕截图所示:

在此处输入图像描述

4

1 回答 1

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>
    )
  }
}
于 2017-10-20T08:14:21.703 回答