[英]object object returns react native
我正在嘗試從 AsyncStorage 獲取數據,但它返回 object object,如何才能正常返回數據? 如果我在 console.log() 中返回數據一切正常,但是當我調用 function 時,它返回 object object。
謝謝
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 />;
}
}
嘗試對其進行字符串化?
console.log(JSON.stringify(apiRequest1));
-----根據您的新更新----您從數據中獲得了黑暗(主題?)?
您可以嘗試以下方法:
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()?
你可以試試。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.