[英]hi i'm using react-native and react-navigation
when i try to navigation.navigate this error occure当我尝试导航时。导航发生此错误
Cannot read property 'navigate' of undefined无法读取未定义的属性“导航”
this is my code这是我的代码
when i try to navigation.navigate this error occure当我尝试导航时。导航发生此错误
Cannot read property 'navigate' of undefined无法读取未定义的属性“导航”
this is my code这是我的代码
const Card = ({
navigation,
item,
ingredients1,
ingredients2,
ingredients3,
}) => {
console.log("ingredients1:", ingredients1);
console.log("ingredients2:", ingredients2);
console.log("ingredients3:", ingredients3);
const ingredients = ingredients1 + "," + ingredients2 + "," + ingredients3;
const ingre1 = ingredients.split(",");
const ingre = ingre1.filter(function (tem) {
return tem !== null && tem !== undefined && tem !== "";
});
const continents = item.content1 + "," + item.content2 + "," + item.content3;
let score = 0;
for (let i = 0; i < ingre.length; i++) {
if (continents.indexOf(ingre[i]) != -1) {
score += 33;
}
}
const _score = String(score);
const score1 = _score.split(",");
console.log("score1:", score1);
const RecipeButton = useCallback(() => {
navigation.navigate("Explain");
}, []);
return (
<>
<ImageStyle
source={{ uri: `http://10.0.2.2:3065/${item.Images[0].src}` }}
/>
<Explain>
<Username>{item.User.nickname}</Username>
<FoodName>{item.name}</FoodName>
<Ingrepercent>재료 {score1}%일치</Ingrepercent>
<Recipe onPress={RecipeButton}>
<Label>Recipe</Label>
</Recipe>
</Explain>
</>
);
};
export default Card;
const MainNavigator = () => {
return (
<Stack.Navigator>
<Stack.Screen
name="Main"
component={Main}
options={{
headerShown: false,
}}
/>
<Stack.Screen
name="Food"
component={Food}
options={{
headerShown: false,
}}
/>
<Stack.Screen
name="Explain"
component={Explain}
options={{
headerShown: false,
}}
/>
<Stack.Screen
name="Card"
component={Card}
options={{
headerShown: false,
}}
/>
</Stack.Navigator>
);
};
i don't know how can i resolve....我不知道我该如何解决......
please help me请帮我
this is error view这是错误视图
This Worked for me!这对我有用!
import { useNavigation } from '@react-navigation/native';
function funcName() {
const navigation = useNavigation();
return (
{/* Your code /*}
);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.