2
WeatherForecast
組件我需要將函數appColor
的返回值傳遞給屬性。然後從WeatherForecast
的財產需要被傳遞到app
組件的className
。新的反應。不知道如何將屬性從子項傳遞給組件。將道具從小孩傳遞給父母React
class WeatherForecast extends Component {
appColor(weatherData) {
//Check for condition and return value
return "example-color1"
}
render() {
/************************************
// Need to Pass returned value of Function into propery or variable?
/************************************/
let bgColor = appColor(weatherData);
return (
<div className="text-center col-xs-12">
<h1 id="temp">{this.displayTemp(this.props.weather)}</h1>
<h1>{this.displayCity(this.props.weather)}</h1>
</div>
);
}
}
export default class App extends Component {
render() {
return (
<div className={"app-container" + this.AppColorPropertyClass}>
<div className="main-wrapper">
<WeatherForecast bgColorPropertyClass={this.AppColorPropertyClass} />
</div>
</div>
);
}
}