Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

136
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda