簡體   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