javascript - ReactJS - super 表达式必须为 null 或函数,而不是未定义

标签 javascript html reactjs

我一直在学习 udemy 上的类(class),但无论我做什么,总是出现一个错误:

enter image description here

这是组件代码:

import React from 'react';
import { Component } from 'react';
import { connect } from 'react-redux';
import Chart from '../components/chart';


class WeatherList extends Component {
  constructor(props) {
    super(props);
  }

  renderWeather(cityData) {
    ...
  }

  render() {
    return (
      ...
    );
  }
}

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

export default connect(mapStateToProps)(WeatherList);

这是我要导入的图表组件:

import React from 'react';
import { Sparklines, SparklinesLine, SparklinesReferenceLine } from 'react-sparklines';
import _ from 'lodash';


function average(data) {
  return _.round(_.sum(data) / data.length);
}

const Chart = (props) => {
  return (
    <div>
      <Sparklines width={80} height={80} data={thisprops.data}>
        <SparklinesLine color={props.color} />
        <SparklinesReferenceLine type="avg" />
      </Sparklines>
      <div>
        { average(props.data) } { props.units }
      </div>
    </div>
  );
};
export default Chart;

但显然 React.Component 未定义,因此它会抛出错误。

最佳答案

我也遇到了同样的问题。该错误是由于 'react-sparklines' 造成的。降级版本:

npm i --save react-sparklines@1.6.0

关于javascript - ReactJS - super 表达式必须为 null 或函数,而不是未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45659966/

相关文章:

html - height=100% 不起作用

javascript - React 中真正的自定义属性(例如微数据)

reactjs - React 中副作用的定义和函数式编程中的一样吗?

javascript - 无法获取数组的长度并且 map() 不适用于该数组

javascript - Vuex 状态和 vue-router

javascript - 将外部链接添加到传单多边形

javascript - 在生产环境中使用 CoffeeScript

javascript - 从函数获取返回值时出现问题

html - Bootstrap 4 下拉项看起来像好友请求

javascript - 如何使用 jQuery 更新文本区域内的代码