这是一个react原生项目.我的编译器发现项变量是未定义的,即使我在函数中使用了项



我正试图在react native中修复我的路由,为此,我使用项变量在页面中导航。

<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>

首先使用{((=>navigation.anavigation("编辑"{id:item.id}(}。如果您在代码中不使用项变量,它将给您未定义的结果。例如,如果您的id变量是person,请尝试使用person.id。在下一页中,请使用route.params.person.

最新更新