1.4 KiB
1.4 KiB
title, localeTitle
| title | localeTitle |
|---|---|
| Pass a Callback as Props | 将回调作为道具传递 |
将回调作为道具传递
描述
- 将
GetInput组件添加到MyApp中的render方法,然后将一个名为inpu的prop从inputValue的状态传递给inputValue。还要创建一个名为handleChange的prop,并将输入处理程序handleChange给它。 - 将
RenderInput添加到MyApp中的render方法,然后创建一个名为input的prop,并将inputValue从state传递给它。
提示
解
class MyApp extends React.Component {
constructor(props) {
super(props);
this.state = {
inputValue: ''
}
this.handleChange = this.handleChange.bind(this);
}
handleChange(event) {
this.setState({
inputValue: event.target.value
});
}
render() {
return (
<div>
{ /* change code below this line */
<GetInput input={this.state.inputValue} handleChange={this.handleChange}/>
}
{ /* change code above this line */
<RenderInput input={this.state.inputValue}/>
}
</div>
);
}
};