enter image description here在使用导航v5时,遇到无法读取未定义属性导航的错误
const Categories =({navigation})=> {
return (
<View >
<Text style={Styles.TextCategories}>دسته بندی ها</Text>
{/* ---------------------------------------------------------------لایه کلی صفحه---------------------------------- */}
<View style={Styles.View}>
{/* --------------------------------------------------------------- لایه دکمه ها---------------------------------- */}
<Button style={Styles.Button} onPress={()=>navigation.navigate('Homesales')}>
<MaterialIcons name="waves" size={30} color={"#0c7656"} />
<Text style={Styles.Text}>زمین</Text>
</Button>
const Home=()=>{
useEffect(()=>{
axios.get('https://jsonplaceholder.typicode.com/posts').then((response)=>console.log(response.data)).catch((e)=>console.log(e))
},[])
return (
<Categories/>
);
}
export default React.memo(Home);
答案 0 :(得分:0)
为什么不使用react-navigation-v5的导航钩?而不是像尝试通过“ useNavigation()”钩子那样传递导航,这样您就可以从任何地方访问有效的导航对象
const navigation = useNavigation()
用于导航 navigation.navigate('')
答案 1 :(得分:0)
您正在将不具有“导航”属性的对象传递给组件类别
您需要检查父组件,这里的道具/导航似乎为空。