0

Tengo un CRUD con una Api rest, para mandar datos uso una función handleChange con onChange, y quiero usar un datepicker que también utilice onChange.

const [tareaSeleccionada, setTareaSeleccionada] = useState({fecha: ""});


const [selectedDate, handleDateChange] = useState(new Date);

const handleChange = (e) => {
const { name, value } = e.target;
setTareaSeleccionada((prevState) => ({
...prevState,
[name]: value,
}));
console.log(tareaSeleccionada);};

¿Cómo llamo a ambos eventos para que agarre la nueva fecha y lo mande a la api en react?

<DatePicker 
label="Fecha"
name="fecha"
format="dd/MM/yyyy"
value={selectedDate}
onChange={handleDateChange ; handleChange}
/>
1
  • ¿Para mandar los datos onChange? ¿Por qué no usar onSubmit en el formulario y lees tus variables de estado al momento de enviar la forma? No veo el problema. Lectura recomendada: Formularios en React el 9 abr. 2022 a las 22:30

1 respuesta 1

0
const [tareaSeleccionada, setTareaSeleccionada] = useState({fecha: ""});


const [selectedDate, setSelectedDate] = useState(new Date());

const handleChange = (e) => {
   const { name, value } = e.target;
   setSelectedDate(value);
   setTareaSeleccionada({
     fecha: value
   })
   console.log(tareaSeleccionada);
};
1

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.