Home > Net >  is there a better way to do this conidition?
is there a better way to do this conidition?

Time:04-05

is there a better way to do this :

      { !AuthState && (
      <NativeStackNavigator.Screen name="Auth" component={Auth} options={{headerShown: false}} />)
      }

      { !AuthState && (
      <NativeStackNavigator.Screen name="XXX" component={XXX} options={{headerShown: false}} />)
      }

      { !AuthState && (
      <NativeStackNavigator.Screen name="XXX" component={XXX} options={{headerShown: false}} />)
      }

thanks for your answer!

CodePudding user response:

You can just use the conditional for all screens once.

{
   !AuthState && (
     <>
      <NativeStackNavigator.Screen name="Auth" component={Auth} options={{headerShown: false}} />
      <NativeStackNavigator.Screen name="XXX" component={XXX} options={{headerShown: false}} />
      <NativeStackNavigator.Screen name="XXX" component={XXX} options={{headerShown: false}} />
   </>
    )
}
  • Related