0
我試圖複選框添加到我的反應成分,但是當我試圖使我從數據拉取從後子它說,功能undifined傳遞功能,其中包含切換
TypeError: Cannot read property 'props' of undefined at WeatherInfo
值來自終極版減速
這是我App.js
toggleCheckboxChange() {
console.log("a");
}
render() {
const { cityName, nameOfCity, weatherDescription, windSpeed, temperature, maxTemperature, minTemperature, toogleValue} = this.props;
let weatherInfo;
weatherInfo = <WeatherInfo
nameOfCity={nameOfCity}
weatherDescription={weatherDescription}
windSpeed={windSpeed}
temperature={temperature}
maxTemperature={maxTemperature}
minTemperature={minTemperature}
toggleValue={toggleValue}
onChange={() => this.toggleCheckboxChange()}
/>;
WeatherInfo組件
const WeatherInfo = (props) => (
<div>
<ul>
<li>{props.nameOfCity}</li>
<li>{props.weatherDescription}</li>
<li>{props.windSpeed} m/s </li>
<li>{props.temperature} °C</li>
<li>{props.maxTemperature}°C</li>
<li>{props.minTemperature}°C</li>
<input
type="checkbox"
checked={props.toogleValue}
onChange={this.props.toggleCheckboxChange}
/>
</ul>
</div>
);
如何傳遞函數的onChange兒童