Super expression must either be null or a function, not undefined when using React-Sparklines
我正在为项目使用第三方组件react-sparklines。 但是,当我如下所示将其导入到我的组件时,它将引发以下错误:Uncaught TypeError:超级表达式必须为null或函数,且未定义。 但是当我将其取出时,错误消失了,应用程序运行平稳。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | 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); |
请注意,我故意省略了
任何帮助将不胜感激!
Sparklines 1.7.0版有一个错误。 考虑降级到较低版本,在本例中为1.6.0版:
1 2 | npm r react-sparklines npm i --save [email protected] |
您可能想在这里获得更多信息:https://github.com/borisyankov/react-sparklines/issues/89
您需要在类中定义构造函数。
1 2 3 | constructor(props){ super(props); } |