反应导航不使用flatlist
“渲染错误。通过逐步措施只能在导航器的视图层次结构上使用。包装组件无法从道具或上下文中访问导航” 当我尝试导航到Prentery,那里有一个列表,这给了我这个错误。当我仅用多个组件替换flatlist时,导航效果很好。
//App.js
const MainStackScreen = () => {
return (
<NavigationContainer>
<MainStack.Navigator
screenOptions={{headerShown: false}}
>
<MainStack.Screen name = "Home" component ={Home}/>
<MainStack.Screen name = "PrEntery" component = {PrEntery}/>
</MainStack.Navigator>
</NavigationContainer>
);
};
export default MainStackScreen;
//Home.js
const Home = ({navigation}) => {
return(
<View style = {{height:'100%',width:'100%',backgroundColor:'#141212'}}>
<SafeAreaView>
<View style={{marginTop:200}}>
<TouchableOpacity onPress={()=>{
navigation.navigate('PrEntery')
}}>
<HomeButton text = 'Enter PR'/>
</TouchableOpacity>
</View>
<View style={{marginTop:40}}>
<TouchableOpacity>
<HomeButton text = 'Record Book'/>
</TouchableOpacity>
</View>
</SafeAreaView>
</View>
);
};
export default Home;
//PrEntery.js
const renderItem = ({index}) => {
return(
<EnterPr text = {index}/>
);
};
const PrEntery = () => {
return(
<View style = {{height:'100%',width:'100%',backgroundColor:'#141212'}}>
<SafeAreaView>
<FlatList
data={LIFTS}
renderItem = {renderItem}
/>
</SafeAreaView>
</View>
);
};
export default PrEntery;
"Render Error. 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"
When I try to navigate to PrEntery where I have a FlatList it is giving me this error. When I replace the FlatList with just multiple components navigation works fine.
//App.js
const MainStackScreen = () => {
return (
<NavigationContainer>
<MainStack.Navigator
screenOptions={{headerShown: false}}
>
<MainStack.Screen name = "Home" component ={Home}/>
<MainStack.Screen name = "PrEntery" component = {PrEntery}/>
</MainStack.Navigator>
</NavigationContainer>
);
};
export default MainStackScreen;
//Home.js
const Home = ({navigation}) => {
return(
<View style = {{height:'100%',width:'100%',backgroundColor:'#141212'}}>
<SafeAreaView>
<View style={{marginTop:200}}>
<TouchableOpacity onPress={()=>{
navigation.navigate('PrEntery')
}}>
<HomeButton text = 'Enter PR'/>
</TouchableOpacity>
</View>
<View style={{marginTop:40}}>
<TouchableOpacity>
<HomeButton text = 'Record Book'/>
</TouchableOpacity>
</View>
</SafeAreaView>
</View>
);
};
export default Home;
//PrEntery.js
const renderItem = ({index}) => {
return(
<EnterPr text = {index}/>
);
};
const PrEntery = () => {
return(
<View style = {{height:'100%',width:'100%',backgroundColor:'#141212'}}>
<SafeAreaView>
<FlatList
data={LIFTS}
renderItem = {renderItem}
/>
</SafeAreaView>
</View>
);
};
export default PrEntery;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论