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

135
Views
State not storing input data if value is given

I am trying to have an initial value in my input field before the user edits it. But when an initial value is given, it does erase when I try to remove it.

<Input
  type="text"
  placeholder={
  title === "" && fieldsFilled === false
  ? "This is a required field"
  : "Enter Title"
  }
  id="title"
  onChange={(e) => setTitle(e.target.value)}
  style={
  title === "" && fieldsFilled === false
  ? styles
  : null
  }
/>

Why is my state not updating when I change. What is wrong with the onChange?

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

0

Dont add initial value on placeholder use value to add it and initial value should come from hook as below

const [title, setTitle] = useState('initial value')

<Input
  type="text"
  placeholder={
  title === "" && fieldsFilled === false
  ? "This is a required field"
  : "Enter Title"
  }
  id="title"
  value = {title}
  onChange={(e) => setTitle(e.target.value)}
  style={
  title === "" && fieldsFilled === false
  ? styles
  : null
  }
/>

look on how i added the value = {title} on input tag, thats the key

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!