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

334
Visualizações
react-datetime - Can't edit Date or Time

When clicked on the input box and type something valid, input will clear or some random date and time will assign to this input.

It is allowing me to select date or time with mouse. Whenever type, input will clear or assign random values.

<Datetime
  value={moment(date)}
  onChange={(date) => setDate(date)}
  dateFormat="DD/MM/YYYY"
  timeFormat="HH:mm:ss"
  utc={true}
/>

When trying with "defaultValue" instead of "value", this will allow to type date or time but it will not appear the value of "date" which i passed through my react state.

<Datetime
  defaultValue={moment(date)}
  onChange={(date) => setDate(date)}
  dateFormat="DD/MM/YYYY"
  timeFormat="HH:mm:ss"
  utc={true}
/>

Image Reference

date picker

  • Version of react-datetime -> "react-datetime": "^2.16.3",
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Your top example is correct. You've build a 'controlled component'. The date is stored in your date state variable. Any time a change occurs that value is updated and the element will be re-rendered. When the element renders, it displays the value.

The issue is you're sending the raw user input to the Moment library, and it's returning a weird date/time. You'll need to "fix" the user's input before passing it into Moment and honestly there's no reason to do that much work. I'd hunt around the internet and find a better date/time component. (Also Moment is considered old. People prefer date-fns these days.)

See also: React controlled component

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