繁体   English   中英

在子组件中更新/编辑后如何重新渲染父组件React Native?

[英]How to re-render parent component React Native after update/edit in Child Component?

更新子组件(ProfileEdit)中的数据后,我在父组件(Profile)中获取新数据时遇到问题,在这里我创建了一个简单的脚本以便于理解,默认组件是Profile,为什么从中返回后无法在Profile中显示警报ProfileEdit,请提供建议或更正我的脚本,以便从ProfileEdit返回后如何显示警报。

Profile.js

export default class Profile extends Component { 
    componentDidMount() {
        alert('Success');
    }

    toProfileEdit() {
        this.props.navigation.navigate('ProfileEdit');  
    }

    render() {
        return (
            <View>
                <Button
                    onPress={() => this.toProfileEdit()}
                    title="Learn More" />
            </View>
        )
    }
}

ProfileEdit.js

export default class ProfileEdit extends Component { 
    backTo() {
        this.props.navigation.navigate('Profile');
    }

    render() {
        return (
            <View>
                <Button
                    onPress={() => this.backTo()}
                    title="Learn More" />
            </View>
        )
    }
} 

请任何人帮助我解决此问题。

谢谢。

配置文件已安装,然后componentWillMount将不会在后退操作上再次调用。 您可以通过prop动作传递函数。

 export default class ProfileEdit extends Component { 
  backTo() {
    this.props.navigation.navigate('Profile');
  }
  render() {
    return (
      <View>
        <Button
          onPress={() => { this.props.something(); this.backTo()}}
          title="Learn More" />
      </View>
    )
  }
}

传递函数的名字是什么 ,叫什么你可以回去了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM