1.6 KiB
1.6 KiB
title, localeTitle
| title | localeTitle |
|---|---|
| Pass a Callback as Props | تمرير رد الاتصال على النحو الدعائم |
تمرير رد الاتصال على النحو الدعائم
وصف
- إضافة مكون
GetInputإلى طريقةGetInputفي MyApp ، ثم تمريرها دعامة تسمىinput المعينة إلىinputValueمن حالة MyApp. أيضا إنشاء دعامة تسمىhandleChangeوتمريرhandleChangeمعالجhandleChangeذلك. - إضافة
RenderInputإلى طريقةRenderInputفي MyApp ، ثم إنشاء دعم يسمىinputوتمريرinputValueمن حالة إليه.
إشارة
stateهي خاصية من فئةMyapp، لذلك استخدم "this.state" للحصول على قيمة الكائن- لمعرفة المزيد عن الحالة والدعائم ، اقرأ State and Lifecycle and Components and Props .
حل
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>
);
}
};