嗨,我正在尝试实现导航,但我一直收到错误
Invariant Violation: withNavigation can only be used on a view hierarchy of a navigator. The wrapped component is unable to get access to navigation from props or context.
这是我的代码,适用于以前版本的反应导航
import { View, StyleSheet, Text } from "react-native"
import { NavigationEvents } from 'react-navigation';
const Home = (props) =>{
return (<View>
<NavigationEvents
onWillFocus={()=>{
console.log("onwillfocus")
}}
onDidFocus={() =>{
console.log("onDidFocus")
}}
/>
<Text>Hello world</Text>
</View>)
}
export default Home
如果您需要检测屏幕是否聚焦,React Navigation 6将暴露一个简单的useIsFocused
挂钩-https://reactnavigation.org/docs/use-is-focused/