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

168
Views
Why event.preventDefault() function is so important?

I have faced a problem when I create a form in react for authentication. Without using event.preventDefault() nothing has happened when I click the submitted button. But when I use this it works fine. What is the reason behind this?

here is my code

const Login = () => {
  const signinWithGoogle=(e)=>{

      e.preventDefault(); // this is my Question

      console.log('click me');
      const provider = new GoogleAuthProvider();
      signInWithPopup(auth,provider)
      .then((result)=>{
          console.log(result);
      })
      .then((error)=>{
          console.log(error);
      })
  }
  return (
      <div>
      <Form >
      <Form.Group className="mb-3 w-50 m-auto " controlId="formBasicEmail">
        <Form.Label>Email address</Form.Label>
        <Form.Control type="email" placeholder="Enter email" />
        <Form.Text className="text-muted">
          We'll never share your email with anyone else.
        </Form.Text>
      </Form.Group>
    
      <Form.Group className="mb-3 w-50 m-auto " controlId="formBasicPassword">
        <Form.Label>Password</Form.Label>
        <Form.Control type="password" placeholder="Password" />
      </Form.Group>
      <Form.Group className="mb-3 m-auto w-50" controlId="formBasicCheckbox">
        <Form.Check type="checkbox" label="Check me out" />
        <Button variant="primary" type="submit" className=''>
        Submit
        </Button>
      </Form.Group>
      <div>
      
      <button className="btn btn-primary" onClick={signinWithGoogle}>Google Signin</button>
      </div>

    </Form>
     
      </div>
  )}; 
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The default behavior of a HTML form element is to submit the contents of that form to a server, process them there, and then load a new HTML page with the result.

Since you are instead processing the form in your client-side application code, you want to prevent this default behavior, and then show the result from your JavaScript code.

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!