Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

190
Vistas
reactjs clear date input after clicking clear button

What should I do to clear date input?, I have button that if the user clicked, it will clear the date.

  const [startdate, setStartDate] = useState();
  const [endDate, setEndDate] = useState();


  const onChangedate = (e) => {
      let startDate = convertDate(e.startDate);
      let endDate = convertDate(e.endDate);
      setStartDate(startDate);
      setEndDate(endDate);
  }; 
  const handleClearfilter = () =>{
    setStartDate("");
    setEndDate("");
  }

  <DateRangePickerComponent   placeholder='Select a range' change={onChangedate} 
              style={{paddingTop: 10, fontSize: 16}}
              />


 <Button 
    onClick={handleClearfilter}
  >
  Clear All
  </Button>

enter image description here

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

I suggest using a React key to "reset" the uncontrolled input. When the React key changes React will throw away the old version and mount a new "instance".

See fully uncontrolled component with a key for example and deeper explanation.

const [key, setKey] = useState(false);

...

const handleClearfilter = () =>{
  setStartDate("");
  setEndDate("");
  setKey(k => !k); // toggle React key value
}

<DateRangePickerComponent
  key={key} // <-- attach React key
  placeholder='Select a range'
  change={onChangedate} 
  style={{paddingTop: 10, fontSize: 16}}
/>
about 4 years ago · Juan Pablo Isaza Denunciar

0

If you want to control the component, you have to feed in the values yourself. The docs show that you require two date values since it is a data range input.

  const [startdate, setStartDate] = useState();
  const [endDate, setEndDate] = useState();


  const onChangedate = (e) => {
      let startDate = convertDate(e.startDate);
      let endDate = convertDate(e.endDate);
      setStartDate(startDate);
      setEndDate(endDate);
  }; 
  const handleClearfilter = () =>{
    setStartDate("");
    setEndDate("");
  }

  <DateRangePickerComponent   placeholder='Select a range' change={onChangedate}   startDate={startDate} endDate={endDate}
              style={{paddingTop: 10, fontSize: 16}}
              />


 <Button 
    onClick={handleClearfilter}
  >
  Clear All
  </Button>


about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda