UNPKG

@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

40 lines 1.58 kB
"use strict"; exports.__esModule = true; exports.LogoutPage = void 0; var react_1 = require("react"); var react_router_dom_1 = require("react-router-dom"); var react_toastify_1 = require("react-toastify"); var auth_api_1 = require("../redux/api/auth-api"); var LogoutPage = function () { // 👇 API Login Mutation var _a = (0, auth_api_1.useLogoutUserMutation)(), logoutUser = _a[0], _b = _a[1], isLoading = _b.isLoading, isError = _b.isError, error = _b.error, isSuccess = _b.isSuccess; var navigate = (0, react_router_dom_1.useNavigate)(); (0, react_1.useEffect)(function () { if (isSuccess) { react_toastify_1.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 react_toastify_1.toast.error(el.message, { position: 'top-right' }); }); } else { react_toastify_1.toast.error(error.data.message, { position: 'top-right' }); } } // eslint-disable-next-line react-hooks/exhaustive-deps }, [isLoading]); (0, react_1.useEffect)(function () { logoutUser(); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); return null; }; exports.LogoutPage = LogoutPage; //# sourceMappingURL=logout.page.js.map