import { useCallback, useRef, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
/**
* @description Get me API hook. Perform the get me API call when component mounted
* @returns {Object}
*/
const useLogout = () => {
const dispatch = useDispatch();
const token = useSelector(selectAccessToken());
const Loading = useRef(GlobalLib.Loading.get());
const callLogout = useCallback(async () => {
try {
Loading.current.show();
await ApiLib.authApi.postApiV1AuthLogout(
UtilLib.getAuthorizationHeaders(token),
);
dispatch(updateAccessToken(null));
dispatch(updateUser({}));
NavigationServiceLib.reset(screens.Launch);
} catch (error) {
} finally {
Loading.current.hide();
}
}, [dispatch, token]);
return {
logout: callLogout,
};
};
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter