I am getting this error. It seems like the promise is unresolved. However, I am unsure how to fix this... I am using Async Storage
Error:
Objects are not valid as a React child (found: object with keys {_40, _65, _55, _72}).
Here is my code
const ProfileStackScreen = ({navigation}) => {
return (<ProfileStack.Navigator>
<ProfileStack.Screen name= {"Profile"} component={Profile}
options ={{
title: AsyncStorage.getItem('username'),
headerRight: () => (
<Icon name="cog" color={"grey"} size={26} style={{marginRight: 20}}
onPress={() => navigation.navigate("Settings")}/>
),
headerLeft: () => (
<Icon name="users" color={"grey"} size={23} style={{marginLeft: 20}}
onPress={() => navigation.navigate("ManageFriends")}/>
)
}}/>
<SettingsStack.Screen name="Settings" component={Settings}/>
<ManageFriendsStack.Screen name="ManageFriends" component={ManageFriends}/>
</ProfileStack.Navigator>);
}
Edit 1:
I noticed I can do something like this
const ProfileStackScreen = ({navigation}) => {
AsyncStorage.getItem('username').then(name => {
//comment
console.log(name);
});
return (<ProfileStack.Navigator>
<ProfileStack.Screen name= {"Profile"} component={Profile}
options ={{
title: "hi",
headerRight: () => (
<Icon name="cog" color={"grey"} size={26} style={{marginRight: 20}}
onPress={() => navigation.navigate("Settings")}/>
),
headerLeft: () => (
<Icon name="users" color={"grey"} size={23} style={{marginLeft: 20}}
onPress={() => navigation.navigate("ManageFriends")}/>
)
}}/>
<SettingsStack.Screen name="Settings" component={Settings}/>
<ManageFriendsStack.Screen name="ManageFriends" component={ManageFriends}/>
</ProfileStack.Navigator>);
}
However, I want to set the name inside my title (line 5) I cant do this.setState since I get (setState of undefined) and I can't put return inside the //comment since I get "cant find return statement"
Any ideas how I can achieve this?
EDIT 2
Tried adding navigation.setOptions
const ProfileStackScreen = ({navigation}) => {
AsyncStorage.getItem('username').then(name => {
navigation.setOptions({title: name});
});
return (<ProfileStack.Navigator>
<ProfileStack.Screen name= {"Profile"} component={Profile}
options ={{
headerRight: () => (
<Icon name="cog" color={"grey"} size={26} style={{marginRight: 20}}
onPress={() => navigation.navigate("Settings")}/>
),
headerLeft: () => (
<Icon name="users" color={"grey"} size={23} style={{marginLeft: 20}}
onPress={() => navigation.navigate("ManageFriends")}/>
)
}}/>
<SettingsStack.Screen name="Settings" component={Settings}/>
<ManageFriendsStack.Screen name="ManageFriends" component={ManageFriends}/>
</ProfileStack.Navigator>);
}
However, it gets override by the name= {"Profile"}
It shows Profile instead of my username.