Ich benutze React-Navigation für Routen verwalten. Das ist mein Hauptkomponente:Update-Status, wenn Benutzer drücken Sie die Taste in reagieren Native
class HomeScreen extends React.Component {
constructor(props) {
this.state = {
userProfile: {
firstname: 'John',
avatar: 'john-profile.png',
location: 'Canada',
}
}
}
componentDidMount() {
AsyncStorage.getItem('userProfile', (errs, result) => {
this.setState({userProfile: JSON.parse(result)});
});
}
render() {
return (
<View>
<Image src="{this.state.userProfile.avatar}" />
<Text>Firstname: {this.state.userProfile.firstname}</Text>
<Text>Location: {this.state.userProfile.location}</Text>
</View>
);
}
}
Und dies ist der Bildschirm Profil:
class ProfileScreen extends React.Component {
constructor(props) {
this.state = {
userProfile: null,
}
}
componentDidMount() {
AsyncStorage.getItem('userProfile', (errs, result) => {
this.setState({userProfile: JSON.parse(result)});
});
}
save() {
var userSavedProfile = this.state.userProfile;
userSavedProfile.firstname = "Peter";
userSavedProfile.avatar = "peter-avatar.png";
userSavedProfile.location = "EEUU";
this.setState({userProfile: userSavedProfile});
AsyncStorage.setItem('userProfile', JSON.stringify(this.state.userProfile),() => {});
}
render() {
return (
<View>
<Button title="Save" onPress={() => this.save()} />
</View>
);
}
}
Wenn ich die neuen Benutzerinformationen speichern und ich drücken Sie die Taste in Header zurück (reagieren-Navigation) das Benutzerprofil alt, Vorname = John, etc ... Wie Update-Status von Home, wenn Benutzer drücken Sie die Taste und aktualisieren Daten?
ich auch das gleiche Problem konfrontiert wurde ändern kann, aber ich gelöst es. Können Sie mir bitte sagen, wie gehen Sie zum Profilbildschirm? Ist home eine Elternklasse für den Profilbildschirm? –
Bitte lassen Sie mich wissen, dann werde ich meinen Code hier posten. –