我得到以下错误:可能未处理的承诺拒绝(id:0:网络请求失败)有时错误id更改为id:3。有人能帮我吗?
从“React”导入React,{useState,useEffect};从“React-Native”导入{SafeAreaView,StyleSheet,Image,AsyncStorage};
从“../components/SpotList”导入SpotList;
从“../assets/logo.png”导入徽标;
导出默认函数列表(){
const [techs, setTechs] = useState ([]);
useEffect(() => {
AsyncStorage.getItem('techs')
.then((storagedTechs) => {
const techsArray = storagedTechs.split(',').map(tech => tech.trim())
setTechs(techsArray)
})
},[]);
return (
<SafeAreaView style={styles.container}>
<Image style={styles.logo} source={logo}/>
{techs.map(tech => <SpotList key={tech} tech={tech}/>)}
</SafeAreaView>
)
}
const styles=stylesheet.create({container:{flex:1,
},
logo: {
height: 32,
resizeMode: 'contain',
alignSelf:'center',
marginTop: 50
},
})
expo go出错
我会尝试在随后的块中添加catch块,比如
null
.then((storagedTechs) => {
const techsArray = storagedTechs.split(',').map(tech => tech.trim())
setTechs(techsArray)
})
.catch(err => {
if (err) console.error(err);
});