【发布时间】:2020-07-10 11:08:40
【问题描述】:
根据 activeStorage 上设置的条件,尝试在 typescript expo 上返回不同的函数(带有视图)。
如果您查看代码,当 showIntro 被调用时,我想显示从 getScreen 返回的值,但是,当我控制台日志时,它返回一个承诺对象
当我在getScreen 中控制台记录await AsyncStorage.getItem('showIntro'); 时,它给了我价值。
不知道是bug还是代码有问题?
import AsyncStorage from '@react-native-community/async-storage'
const data = [{...}, {...}, {...}]
const getScreen = async () => {
return await AsyncStorage.getItem('showIntro');
}
function App() {
const [showIntro, updateShowIntro] = React.useState(getScreen());
const onDone = () => {
AsyncStorage.setItem('showIntro', false).then(()=>{});
updateShowIntro(false);
}
return (
{ (showIntro) ? (
<AppIntroSlider
renderItem={renderItem}
data={data}
onDone={onDone}/>
) : (
<ShowApp />
)
}
);
}
【问题讨论】:
标签: javascript typescript async-await expo asyncstorage