2017-08-10 30 views
4

我正在爲項目使用第三方組件react-sparklines。但是,如下所示,將其導入到我的組件時,會引發以下錯誤:未捕獲的TypeError:超級表達式必須爲null或函數,而不是未定義的。但是當我把它拿出來時,錯誤消失了,應用程序運行順利。超級表達式必須爲null或函數,在使用React-Sparklines時未定義。

import React, {Component} from 'react'; 
import {connect} from 'react-redux'; 
import { Sparklines, SparklinesLine } from 'react-sparklines'; 

class WeatherList extends React.Component{ 
    renderCity(cityData){ 
    const name = cityData.city.name; 
    const temps = cityData.list.map(weather => weather.main.temp); 

    return (
     <tr key={name}> 
     <td>{name}</td> 
     <td> 
<Sparklines data={[5, 10, 5, 20]}> 
    <SparklinesLine color="blue" /> 
</Sparklines> 
     </td> 
     </tr> 
    ); 
    } 
} 

function mapStateToProps(state){ 
    return { weather: state.weather };} 

export default connect(mapStateToProps)(WeatherList); 

請注意我故意忽略render()函數。以下是Sparklines的鏈接:https://github.com/borisyankov/react-sparklines

任何幫助將不勝感激!

回答

-1

你需要在你的類中定義構造函數。

constructor(props){ 
    super(props); 
} 
+1

不,你在這種情況下沒有。 – ZeroDarkThirty

相關問題