Open SuperProgrammer775 opened 4 years ago
withAuth.js:
import useAuth from "../customHooks/index.js"; import { withRouter } from "react-router-dom";
const WithAuth = (props) => useAuth(props) && props.children;
export default withRouter(WithAuth);
useAuth.js:
import { useEffect } from "react"; import { useSelector } from "react-redux";
const mapState = ({ user }) => ({ currentUser: user.currentUser, });
export const useAuth = (props) => { const { currentUser } = useSelector(mapState);
useEffect(() => { if (!currentUser) { props.history.push("/login"); } }, [currentUser]);
return currentUser; };
index.js:
import { useAuth } from "./useAuth.js";
export default { useAuth };
plz help🙏
Link 2 file errors: LINK
withAuth.js:
import useAuth from "../customHooks/index.js"; import { withRouter } from "react-router-dom";
const WithAuth = (props) => useAuth(props) && props.children;
export default withRouter(WithAuth);
useAuth.js:
import { useEffect } from "react"; import { useSelector } from "react-redux";
const mapState = ({ user }) => ({ currentUser: user.currentUser, });
export const useAuth = (props) => { const { currentUser } = useSelector(mapState);
useEffect(() => { if (!currentUser) { props.history.push("/login"); } }, [currentUser]);
return currentUser; };
index.js:
import { useAuth } from "./useAuth.js";
export default { useAuth };
plz help🙏