I was sending all the data of my form to an api, but I can't do it, this is my code
const handleSubmit = () => {
setData({
...data,
apellidoParterno: inputs.apellidoParterno,
apellidoMaterno: inputs.apellidoMaterno,
nombres: inputs.nombres,
cargocontacto: inputs.cargocontacto,
telèfonocontacto: inputs.telèfonocontacto,
celularcontacto: inputs.celularcontacto,
emailcontacto: inputs.emailcontacto,
})
onSubmitProveedor();
}
the information is stored correctly in setData, but the problem is that it takes a little time to do that and that is why what I send to the api is nothing. This function "onSuibmitProveedor" is my function where I am sending the data
Yes,
setStateis asynchronous; you can't read the updateddataimmediately.You can either call
onSubmitProveedorfrom an effect, e.g.or make
onSubmitProveedoraccept the data object and call it directly there: