Home > Blockchain >  how to use navigate in react with react-redux
how to use navigate in react with react-redux

Time:02-26

I am making a login foam on react using react-redux, kindly suggest to me how I will use navigate here

const { isAuthenticated, error, loading} = useSelector(state =>state.auth);
  useEffect(()=>{
    if(isAuthenticated){
      navigate("/dashboard");
    }
    if(error){
      // alert.error(error);
      dispatch(clearErrors());
    }
  },
  // [dispatch,alert,isAuthenticated,error,navigate]
  [dispatch,isAuthenticated,error,navigate]
  )

enter image description here

CodePudding user response:

Did you import useNavigate at the top of the file like this?

import { useNavigate } from "react-router-dom";

Then, to use it, assign it to a variable:

let navigate = useNavigate();

then use it like you have in the code: navigate("/dashboard");

  • Related