2017-10-20 117 views
0

所以我有自定義組件class App,但仍然有問題。確定這件事很容易,但對於我這樣的人來說,我沒有搞清楚。基本上,我的代碼是:React中的奇數語法錯誤

(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一個示例項目新的東西,但現在得到這個如圖截圖:

enter image description here

+2

你'onEventClick = {(目標,EVENTDATA,日)} =>執行console.log(EVENTDATA)'行都有錯了地方花關閉,它應該在日誌之後。這是我在這段代碼中看到的唯一錯誤。 – loganfsmyth

+0

不變的錯誤通常是由於嘗試渲染未正確導入的組件造成的。在這種情況下,它看起來像你正在使用的[react-event-calendar](https://github.com/dptoot/react-event-calendar)包是很老的,似乎不被支持。如果你從渲染中移除了這個組件,我想你的應用程序將會工作,並且我建議找一個更新的組件。 –

+0

@AustinGreco - 告訴我,事件日曆組件或react-babel初學者應用程序是從哪裏開始的?最近似乎並沒有那麼古老並且有過活動。我試圖改變組件渲染無濟於事。 – Mark

回答

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> 
    ) 
    } 
}