【问题标题】:Super expression must either be null or a function, not undefined when using React-Sparklines超级表达式必须为 null 或函数,在使用 React-Sparklines 时未定义
【发布时间】:2018-01-18 04:09:01
【问题描述】:

我正在为一个项目使用第三方组件 react-sparklines。但是,当我将其导入到我的组件中时,如下所示,它会引发以下错误:Uncaught TypeError: Super expression must be null or a function, not undefined。但是当我取出它时,错误消失了,应用程序运行顺利。

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

任何帮助将不胜感激!

【问题讨论】:

    标签: reactjs react-redux


    【解决方案1】:

    你需要在你的类中定义构造函数。

    constructor(props){
      super(props);
    }
    

    【讨论】:

    • 不,在这种情况下你不需要。
    【解决方案2】:

    Sparklines 1.7.0 版有一个错误。考虑降级到较低版本,在本例中为 1.6.0 版:

    npm r react-sparklines
    npm i --save react-sparklines@1.6.0
    

    您可能想在此处获取更多信息:https://github.com/borisyankov/react-sparklines/issues/89

    【讨论】:

    • 这是为我做的!非常感谢。
    猜你喜欢
    • 2016-10-07
    • 1970-01-01
    • 1970-01-01
    • 2021-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-20
    • 1970-01-01
    相关资源
    最近更新 更多