you can create a component to make redirection after cleaning storage :
import { NavigationEvents } from 'react-navigation';
class Logout extends Component {
_clearAsyncStorage = async () => {
AsyncStorage.clear();
};
render() {
const { navigate } = this.props.navigation;
return (
<View>
<Text>Logout</Text>
<NavigationEvents onDidFocus={() => navigate('Login')} />
</View>
);
}
}
Make sur that you have created your navigation inside the navigation component :
you can use react navigation v4 or v5 to create a stack navigation :
For me a added the logout link inside a drawer :
const AppDrawerNavigator = createDrawerNavigator(
.... other components
Déconnexion: {
screen: Logout,
navigationOptions: {
drawerIcon: ({ tintColor }) => (
<Icon
name={Platform.OS === 'ios' ? 'ios-exit' : 'md-exit'}
size={30}
style={styles(tintColor).drawerIcons}
type="material"
/>
),
},
)