I was trying the useEffect example something like below:
const navigation = () => {
const [isLogin, setLodin] = useState(undefined)
useEffect( async () => {
const username = await AsyncStorage.getItem('username')
if(username){
setLodin(true)
console.log(username)
}else{
setLodin(false)
}
},[])
if (isLogin === undefined){
return (
<View style={{flex:1, justifyContent: 'center', alignItems: 'center'}}>
<ActivityIndicator />
</View>
)
}
return (
<NavigationContainer>
<Stack.Navigator screenOptions={{headerShown: false}}>
{
isLogin ? (
<Stack.Screen
name="HomeBtmTabNavigation"
component={HomeBtmTabNavigation}
/>
) : (
<>
<Stack.Screen name="LandingScreen2" component={LandingScreen2} />
<Stack.Screen name="LoginScreen" component={LoginScreen} />
<Stack.Screen name="SignUpScreen" component={SignUpScreen} />
<Stack.Screen name="SignUpSuccScreen1" component={SignUpSuccScreen1} />
<Stack.Screen name="SignUpSuccScreen2" component={SignUpSuccScreen2} />
</>
)
}
</Stack.Navigator>
</NavigationContainer>
); };
But Warning Comes Up's: useEffect must not return anything beside a function, which is used for clean-up Error Comes up Every Screen.