Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

134
Views
Redirect from a Register Form with React Class in v6

I'm doing a register form in React using a class and I would like to send the user to another page when the register is correct, the problem is that I haven't find any functional way to make it.

.then(data => {
            if(data.error != null) {
                console.log("Error => "+data.error);
            } else {
                //Send the user to the login page
            }
        })

This is the part where I would send him to the login page, I have proved with 'useNavigation' and some more, but I can't find the correct way to get it.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Since react-router-dom v6 supports only hooks. For implementing the navigate functionality inside a class-based component, you have to create a HOC and pass the hooks as props.

// withRouter.js

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

export const withRouter = (Component) => {
  const Wrapper = (props) => {
    const navigate = useNavigate();
    // any other hooks can be added and passed on
    return (
      <Component
        navigate={navigate}
        {...props}
        />
    );
  };
  
  return Wrapper;
};

then on your RegisterForm.jsx you can

import {withRouter} from './withRouter';

class RegisterForm extends React.Component{
//...

 yourFunction =() =>{

   .then(data => {
        if(data.error != null) {
           console.log("Error => "+data.error);
         } else {
           //Send the user to the login page
           this.props.navigate('/loginPage'); 
         }
     })
 }
//...

}

export default withRouter(RegisterForm);

(https://github.com/remix-run/react-router/issues/7256)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!