【发布时间】:2020-07-23 09:37:36
【问题描述】:
完整的错误文本
错误:对象作为 React 子对象无效(找到:带有键 {_40、_65、_55、_72} 的对象)。如果您打算渲染一组子项,请改用数组。
renderFeed = async (item) => {
let token = await localStorage.getItem('userToken')
let data = await axios
.get(ReactionsURL, {
headers: {
"token": token,
},
})
.then((responseData) => {
console.log("responseData", responseData);
// Scope to use reactions
})
.catch((error) => {});
const imgsrc =item.item.photo == null ? "../photos/defaultAvatar.png" : item.item.photo;
return (
<TouchableHighlight
underlayColor="#F6F8FC"
onPress={() =>
navigation.navigate({
name: "Details",
params: {
nav: navigation,
id: item.item._id,
},
})
}
>
<View style={styles.styleCard}>
<View style={styles.TextWrapper}>
<Title
numberOfLines={4}
ellipsizeMode="tail"
style={styles.styleTitle}
>
{item.item.title}
</Title>
<Paragraph style={styles.Textdate}>
{parseInt(new Date().getFullYear()) ===
parseInt(moment(item.item.lastEdit).format("Y"))
? moment(item.item.lastEdit).format("dddd Do MMMM")
: moment(item.item.lastEdit).format("dddd Do MMMM Y")}
</Paragraph>
</View>
<Surface style={styles.Viewphoto}>
<Image source={{ uri: imgsrc }} style={styles.photo} />
</Surface>
</View>
</TouchableHighlight>
);
};
我没有任何对象作为 React 孩子,我该如何解决这个错误?
【问题讨论】:
-
this : 带有键 {_40,_65,_55,_72} 的对象是一个未解决的承诺。删除 async/await 。处理异步情况我推荐这篇文章:medium.com/capbase-engineering/…