Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in %s.%s, a useEffect cleanup function,
const Drawer = createDrawerNavigator();
const App = () => {
const [isLoading, setIsLoading] = React.useState(true);
const [userToken, setUserToken] = React.useState(null);
const authContext = React.useMemo(() => ({
SignIn: () => {
setUserToken('qwertyuiop');
setIsLoading(false);
},
SignOut: () => {
setUserToken(null);
setIsLoading(false);
},
SignUp: () => {
setUserToken('qwe');
setIsLoading(false);
},
}));
useEffect(() => {
setTimeout(() => {
setIsLoading(false);
}, 1000);
}, []);
if (isLoading) {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<ActivityIndicator size="large" />
</View>
);
}
console.log("userToken", userToken)
console.log("authContext", authContext)
return (
<AuthContext.Provider value={authContext}>
<NavigationContainer>
{userToken !== null ? (
<Drawer.Navigator drawerContent={props => <DrawerContent {...props} />}>
<Drawer.Screen name="HomeDrawer" component={MainTabScreen} />
<Drawer.Screen name="Support" component={SupportScreen} />
<Drawer.Screen name="Setting" component={SettingScreen} />
<Drawer.Screen name="Bookmark" component={BookmarkScreen} />
</Drawer.Navigator>
)
:
<RootStackScreen />
}
</NavigationContainer>
</AuthContext.Provider>
);
}