我一直在遵循关于udemy的课程,但是无论我做什么,都会出现一个错误:

以下是组件代码:
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没有定义,所以它会抛出一个错误。
发布于 2017-11-19 14:13:42
我也有同样的问题。臭虫是由“反应-火花”引起的。通过以下方式将该版本降级:
npm i --save react-sparklines@1.6.0。
发布于 2017-08-13 12:08:43
经过进一步的检查,当您试图访问组件中一个未定义的thisprops对象时,您的thisprops组件中似乎出现了问题。
所以,它应该是:data={thisprops.data},而不是data={props.data}。
https://stackoverflow.com/questions/45659966
复制相似问题