I have JS class (React component) which was created for displaying forecasts:
class WeatherList extends Component {
convertDate(date) {
return new Date(date).toLocaleTimeString(['en-US'],
{
hour: 'numeric',
minute: 'numeric'
}
);
}
renderWeather(data) {
const temps = data.list.map(weather => weather.main.temp);
const labels = data.list.map(weather => this.convertDate(weather.dt_txt));
const chartData = {
datasets: [{
data: temps
}],
labels: labels,
}
return (
<tr key={data.city.id}>
<td>
{data.city.name}
</td>
<td>
<Line data={chartData} width="600" height="250"/>
</td>
</tr>
)
}
render() {
return (
<table className='table table-hover'>
<thead>
<tr>
<th>
City
</th>
<th>
Temperature
</th>
</tr>
</thead>
<tbody>
{this.props.weather.map(this.renderWeather)}
</tbody>
</table>
)
}
}
But recently i'v ran into error: this
in this.convertDate(weather.dt_txt)
is undefined
in the renderWeather
function (which renders table row with Chart component).
i'm using webpack to compose all my file and also a babel library.