我正在开发一个 React Native 应用程序,我正在从子组件调用父函数,它被调用但它不会改变状态。基本上我正在从子打开一个模态,并希望通过更改模态上的某些内容并关闭模态来更改父组件的状态。
这是父母:
constructor(props) {
super(props);
this._toggleModal = this._toggleModal.bind(this)
this.state = {
isActive: false}}
_toggleModal = async() => {
this.setState({ isModalVisible: !this.state.isModalVisible })
}
doSomthing(x) {
console.log(x)
this._toggleModal;
}
render() {
return (
<RateModal toggleCall1={this.doSomthing}/>
)}
这是孩子:
ratingCompleted = async(rating)=> {
console.log("Rating is: " + rating)
await this.props.toggleCall1(false)
}
在这里,当给出评分时,我false从孩子那里获得道具,但它不会改变父母的状态。如何解决这个问题?