-
-
Save imranariffin/fcc649a4f30a1f70dc6f50d1873c4832 to your computer and use it in GitHub Desktop.
Not sure if this is possible, but for
PrivateScreen
, why not this instead?const PrivateScreen = ({ isAuthenticated, navigation, component, name }) => { if (!isAuthenticated) { navigation.navigate('Login'); } return <Stack.Screen name={name} component={component} /> }
Agreed, someone else has also pointed out this issue on Reddit.
const PrivateScreen = ({ isAuthenticated, navigation, component, name }) => {
if (!isAuthenticated) {
navigation.navigate('Login')
return null
}
return <Stack.Screen name={name} component={component} />
}
I think your fix would work (plus a one-line amendment as above) but I will try to create a repo to test this when I have time.
Edit: Now the gist has been updated with a fix similar to @hbina's suggestion
Hello , thanks for this code
but i keep receiving this error: Error: A navigator can only contain 'Screen' components as its direct children (found 'undefined' for the screen 'Login')
Is there anyway to resolve it ?
Its been a while since I've use React but it seems like you passed an undefined
value in <Login ...>
. Share some code?
Thanks hbina for responding i've used another method to solve the problem , !
I keep get error Error: A navigator can only contain 'Screen' components as its direct children (found 'undefined' for the screen 'Login')
Not sure if this is possible, but for
PrivateScreen
, why not this instead?