Home > OS >  histrory.push is not working when I am trying to redirect to other page after submiting the Form in
histrory.push is not working when I am trying to redirect to other page after submiting the Form in

Time:10-02

fromComponent.js

 const history = useHistory();
 const handleUserSubmitData = () => {
    history.push("/");
  };

<Form onSubmit={() => handleUserSubmitData}>
  </Form>

After submitting it is redirected to /? not to /. could you please help me out to solve this issue? enter image description here

CodePudding user response:

You aren't calling the handleUserSubmitData function

Update the line as follow

...
<Form onSubmit={() => handleUserSubmitData()}> // call function here by adding parentheses //()
...

Hope this will solve your issue.

  • Related