[英]object object returns react native
I am trying to get data from AsyncStorage, but it returns object object, how I can return data normally?我正在尝试从 AsyncStorage 获取数据,但它返回 object object,如何才能正常返回数据? If i return data in console.log() all is ok, but when I call function it returns object object.
如果我在 console.log() 中返回数据一切正常,但是当我调用 function 时,它返回 object object。
Thanks谢谢
const getTheme = async () => {
try {
const value = await AsyncStorage.getItem('theme');
console.log(value); // returns dark
return JSON.stringify(value)
} catch (error) {
alert(error)
}
};
alert(getTheme()) // [object, object]
const TabNavigator = createBottomTabNavigator(
{
Home: {
screen: Home,
navigationOptions: ({ navigation }) => ({
tabBarLabel: "Home",
tabBarVisible: getActiveRoute(navigation.state) !== "ArticleScreen",
tabBarIcon: ({ tintColor }) => (
<Icon name="ios-home" color={tintColor} size={24} />
)
})
},
Courses: {
screen: Courses,
navigationOptions: {
tabBarLabel: "Courses",
tabBarIcon: ({ tintColor }) => (
<Icon name="ios-school" color={tintColor} size={24} />
)
}
}
},
{}
)
export default createAppContainer(TabNavigator);
class App extends React.Component {
render() {
return <TabNavigator />;
}
}
Try to stringify it?尝试对其进行字符串化?
console.log(JSON.stringify(apiRequest1));
-----According to your new update---- You have got dark(A theme?) from data? -----根据您的新更新----您从数据中获得了黑暗(主题?)?
You could try something like:您可以尝试以下方法:
const getTheme = async () => {
try {
const value = await AsyncStorage.getItem('theme');
console.log(value); // returns dark (Is here a theme?)
return value //Just retrun the value of dark?
} catch (error) {
alert(error)
}
};
alert(getTheme) //Is here have to use getTheme not getTheme()?
You could try it.你可以试试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.