I save an object containing user data like email, username, etc.
I used AsyncStorage to save them, and when I get them I just see a string when I log or use it in my textInput so how to handle this and just get a specific data like Just Email or Just Username I saved?
My Code
Sign Up
const {
username,
email,
city,
mobileNumber,
} = this.state;
const profileData = {
"username": username,
"email": email,
"city": city,
"mobileNumber": mobileNumber
}
firebase
.auth()
.createUserWithEmailAndPassword(email, password)
.then(async user => {
firebase
.database()
.ref(`users/${user.user.uid}`)
.set({
username: username,
type: type,
email: email,
city: city,
mobileNumber: mobileNumber,
token: fcmToken
});
this.props.navigation.navigate("Home");
await AsyncStorage.setItem('@MyProfile:data', JSON.stringify(profileData)).then(() => console.log("Saved"));
}).catch(err => console.log(err));
Profile Screen
async componentDidMount() {
try {
await AsyncStorage.getItem('@MyProfile:data')
.then(data => this.setState({ data }))
.catch(error => console.log('@error' + error));
console.log(this.state.data); //
} catch (error) {
console.log("@CError", error);
}
}
render(){
return(
<View style={styles.logoSection}>
{/* <SvgComponent height={100} /> */}
<Icon name="ios-contact" size={90} color='#4d8dd6' style={{ marginTop: 9 }} />
<Text style={{ fontSize: 18, color: "#000", margin: 35, marginTop: 7 }}>{this.state.data}</Text> // i wnat just display username here from storage
</View>
)
}
Console
console.log(this.state.data);
As a string i think: {"username":"user","email":"user@user.us","city":"usercity","mobileNumber":"0597979979"}