反应导航不使用flatlist

发布于 2025-02-12 21:46:19 字数 1869 浏览 0 评论 0原文

“渲染错误。通过逐步措施只能在导航器的视图层次结构上使用。包装组件无法从道具或上下文中访问导航” 当我尝试导航到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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文