useAuthRoute.js 556 B

123456789101112131415161718192021
  1. import {useLocation} from 'react-router-dom';
  2. import {useEffect, useState} from 'react';
  3. const useAuthRoute = () => {
  4. const authRoutes = ['/login', '/sign-up'];
  5. const location = useLocation();
  6. const [isAuthRoute, setIsAuthRoute] = useState(false);
  7. useEffect(() => {
  8. setIsAuthRoute(authRoutes.includes(location.pathname));
  9. return () => {
  10. setIsAuthRoute(false);
  11. }
  12. // eslint-disable-next-line react-hooks/exhaustive-deps
  13. }, [location]);
  14. return isAuthRoute;
  15. }
  16. export default useAuthRoute