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

69
Views
how to reset input fild without empty string in react.js

How can I reset the input field if I use it this way?

const [email, setEmail] = useState({ email: "", emailError: "" });
   
    const handleEmail = (inputEmail) => {
    if (/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(inputEmail)) {
      setEmail({ email: inputEmail, emailError: "" });
    } else {
      setEmail({ email: "", emailError: "Invalid Email" });
    }
  };

   <Form.Control type="email"  onChange={(e) => handleEmail(e.target.value)} name="email" 
    placeholder="Enter email" />
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use initial state variable, this is one of the best approach to reset states in react. If you want to reset seperately then you can give initial values for email and emailError instead of giving whole initial object

const initialState = {
    email: "",
    emailError: ""
}

const [email, setEmail] = useState(initialState);
    
const reset = () => {
  setEmail(initialState)
}
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!