@rtbjs/use-state
Version:
`@rtbjs/use-state` is a state management tool that can act as a local state and be easily turned into a global redux state. It is an innovative approach to state management that combines the advantages of both React's useState and Redux's state management
37 lines • 1.38 kB
JavaScript
import { useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import { toast } from 'react-toastify';
import { useLogoutUserMutation } from '../redux/api/auth-api';
var LogoutPage = function () {
// 👇 API Login Mutation
var _a = useLogoutUserMutation(), logoutUser = _a[0], _b = _a[1], isLoading = _b.isLoading, isError = _b.isError, error = _b.error, isSuccess = _b.isSuccess;
var navigate = useNavigate();
useEffect(function () {
if (isSuccess) {
toast.success('You are logged out. Please login again if you want to continue using the app.');
navigate('/login');
}
if (isError) {
if (Array.isArray(error.data.error)) {
error.data.error.forEach(function (el) {
return toast.error(el.message, {
position: 'top-right'
});
});
}
else {
toast.error(error.data.message, {
position: 'top-right'
});
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isLoading]);
useEffect(function () {
logoutUser();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
return null;
};
export { LogoutPage };
//# sourceMappingURL=logout.page.js.map