[英]This is a react native project. My compiler finds the item variable to be undefined even though I used item in a function
I am trying to fix my routes in react native, to do so I'm using the item variable to navigate through my pages.我试图在本机反应中修复我的路线,为此我使用 item 变量来浏览我的页面。
<TouchableOpacity
style={{
padding: 20,
flexDirection: "row",
backgroundColor: colors.background,
justifyContent: "flex-end",
alignItems: "center",
}}
onPress={navigation.navigate("Edit", { id: item.id })}
>
<Text style={{ fontSize: 24 }}>Task</Text>
<MaterialCommunityIcons
name="plus"
size={40}
style={{
color: colors.themeColor,
backgroundColor: colors.white,
borderRadius: 20,
marginHorizontal: 8,
}}
/>
</TouchableOpacity>
First use {()=> navigation.navigate("Edit", { id: item.id })}.If you are not using item variables in your code it will give you undefined.首先使用 {()=> navigation.navigate("Edit", { id: item.id })}。如果你没有在你的代码中使用项目变量,它会给你未定义的。 for example, if your id variable is a person so try using person.id.例如,如果您的 id 变量是一个人,那么请尝试使用 person.id。 On the next page use route.params.person.在下一页使用 route.params.person。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.