【发布时间】:2016-11-16 23:19:09
【问题描述】:
在WeatherForecast 组件中,我需要将函数appColor 的返回值传递给属性。然后需要将来自WeatherForecast 的属性传递给app 组件的className。新反应。不知道如何将属性从子组件传递给组件。
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>
);
}
}
【问题讨论】:
标签: javascript reactjs