0

So first this is my code :

const SignIn = (e) => {
      e?.preventDefault()
      if(usernamePattern?.test(this.state.userLoginInfo.username) && emailPattern?.test(this.state.userLoginInfo.email) && passwordPattern?.test(this.state.userLoginInfo.password)) {
        this.setState({...userLoginInfo.isLoggedIn = true})
        storeUserInfo(userLoginInfo);
      }
      if(usernamePattern?.test(userLoginInfo.username) == false){
        usernameErrMsg?.classList.remove('hidden')
        usernameInputBorder?.classList.remove('border-slate-500');
        usernameInputBorder?.classList.add('border-red-600');
      }
      if(emailPattern?.test(userLoginInfo.email) == false){
        emailErrMsg?.classList.remove('hidden')
        emailInputBorder?.classList.remove('border-slate-500');
        emailInputBorder?.classList.add('border-red-600');
      }
      if(passwordPattern?.test(userLoginInfo.password) == false){
        passwordErrMsg?.classList.remove('hidden')
        passwordInputBorder?.classList.remove('border-slate-500');
        passwordInputBorder?.classList.add('border-red-600');
      }
    }

I want to redirect to the '/dashboard' route when the user signs in with the correct info. is there an alternative for 'useNavigate' in class components ? note: {browserHistory} did not work for me.

  • what react router version are you using? – Asplund Feb 24 '23 at 13:01
  • For V6 check this: https://github.com/remix-run/react-router/issues/8146#issuecomment-946638626 . Also, if you're using react-router-dom 5, this should be your solution https://v5.reactrouter.com/web/api/withRouter – noviceGuru Feb 24 '23 at 13:10
  • Thank you, but i am not sure how this would help. because I got an uncaught error: useHistory is not defined and for use navigate is only available in the context of routes – islam gueniari Feb 24 '23 at 14:54
  • please see https://stackoverflow.com/questions/70143135/how-to-use-react-router-dom-v6-navigate-in-class-component – Abbas Bagheri Feb 24 '23 at 16:10

0 Answers0