1

I'm stumbling against this error:

A navigator can only contain 'Screen', 'Group' or 'React.Fragment' as its direct children (found 'Screen' for the screen 'State').

I tried to disable prettier and eslint and make all the screens being each on one line.

If I comment the first screen, the error moves to the third screen (found 'Screen' for the screen 'StateWithSignal') and so on.

dependencies:

"@react-navigation/native": "^6.1.2",
"@react-navigation/native-stack": "^6.9.8",
"@react-navigation/stack": "^6.3.16",
"react-native": "0.71.0",

Here's the code.

import React, {memo} from 'react';
import {createNativeStackNavigator} from '@react-navigation/native-stack';
import {RootNativeStackParamList} from './types';

import {
  HomeScreen,
  StateScreen,
  DecoratorScreen,
  CompositeScreen,
  ObserverScreen,
  CommandScreen,
  ChainOfResponsibilityScreen,
  FacadeScreen,
  StateWithSignalScreen,
  CompositeWithSignalScreen,
} from '../screens';
const Stack = createNativeStackNavigator<RootNativeStackParamList>();

const Navigator = () => (
  <Stack.Navigator>
    <Stack.Screen
      name="Home"
      component={HomeScreen}
      options={{title: 'Home'}}
    />
    <Stack.Screen
      name="State"
      component={StateScreen}
      options={{title: 'State'}}
    />
    <Stack.Screen
      name="StateWithSignal"
      component={StateWithSignalScreen}
      options={{title: 'StateWithSignal'}}
    />
    <Stack.Screen
      name="Decorator"
      component={DecoratorScreen}
      options={{title: 'Decorator'}}
    />
    <Stack.Screen
      name="Composite"
      component={CompositeScreen}
      options={{title: 'Composite'}}
    />
    <Stack.Screen
      name="CompositeWithSignal"
      component={CompositeWithSignalScreen}
      options={{title: 'CompositeWithSignal'}}
    />
    <Stack.Screen
      name="Observer"
      component={ObserverScreen}
      options={{title: 'Observer'}}
    />
    <Stack.Screen
      name="Command"
      component={CommandScreen}
      options={{title: 'Command'}}
    />
    <Stack.Screen
      name="ChainOfResponsibility"
      component={ChainOfResponsibilityScreen}
      options={{title: 'ChainOfResponsibility'}}
    />
    <Stack.Screen
      name="Facade"
      component={FacadeScreen}
      options={{title: 'Facade'}}
    />
  </Stack.Navigator>
);

export default memo(Navigator);
balsick
  • 1,099
  • 1
  • 10
  • 23
  • Did you try the answers on this post? [stackoverflow link](https://stackoverflow.com/questions/67584461/a-navigator-can-only-contain-screen-group-or-react-fragment-as-its-direct) – nevidev Mar 31 '23 at 09:48
  • they don't seem very related to my problem @nevidev. anyway yes, I have tried those related – balsick Mar 31 '23 at 14:17
  • Have you tried removing the memo from the export? – Abe Apr 04 '23 at 00:12
  • eventually I come up with the idea that the problem is the usage of signaljs inside the screens called something "WithSignal". I'll verify that and come back with a more detailed answer – balsick Apr 18 '23 at 08:00

0 Answers0