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

102
Views
Form needs to be submitted twice

I am trying to implement a super simple, super primitive authentication page for my website. The user sees just a single input field and a submit button. If the input matches the password (hashing remains to be added) the user is authenticated.

The problem is, however, that you always have to input the correct string and press the submit button twice. I don't know why this is happening, and it is obviously quite annoying.

Is there any solution for this? All I've found is to use e.preventDefault(), which I am already using, but to no avail.

import { useState } from 'react'
import App from '../App'

export default function Password() {
  const [auth, setAuth] = useState(false)
  const [pass, setPass] = useState("")
  const secret = ""

  const handleChange = e => {
    setPass(e.target.value)
  }

  const handleSubmit = e => {
    e.preventDefault()
    e.nativeEvent.stopImmediatePropagation();
    if (pass === secret) {
      setAuth(true)
    }
  }

  if (auth) {
    return (
      <App/>
    )
  } else {
    return (
      <form onSubmit={handleSubmit}>
        <input style={{ border: "1px solid grey", borderRadius: "4px" }} type="text" value={pass} onChange={handleChange} />
        <input style={{ border: "1px solid grey", borderRadius: "4px" }} type="submit" value="submit" />
      </form>
    )
  }
  
}
about 4 years ago · Juan Pablo Isaza
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!