react set state not working on keyboard dismiss?



我有一个像这样的简单函数,我刚刚从react文档中复制了它,警报工作得很好,但我的函数changeDescription什么都不做,即使我放了一个简单的setstate??我做错了什么?

constructor(props) {
super(props);

this.changeDescription = this.changeDescription.bind(this);
this.sendDescription = this.sendDescription.bind(this);
this._keyboardDidHide = this._keyboardDidHide.bind(this);
}
componentDidMount() {
this.keyboardDidShowListener = Keyboard.addListener(
'keyboardDidShow',
this._keyboardDidShow,
);
this.keyboardDidHideListener = Keyboard.addListener(
'keyboardDidHide',
this._keyboardDidHide,
);
}
componentWillUnmount() {
this.keyboardDidShowListener.remove();
this.keyboardDidHideListener.remove();
}
_keyboardDidHide() {
const { member } = this.props;
alert(member.description)
this.changeDescription('ok')
}

changeDescription = (val) => {
// console.log(val)
this.setState({ description: val })
}

<Textarea
defaultValue={member.description}
onChangeText={v => this.changeDescription(v)}

/> 

我的猜测是,您只需要设置Textarea 的值

<Textarea
defaultValue={member.description}
onChangeText={v => this.changeDescription(v)}
value={this.state.description} />

最新更新