Estoy haciendo un formulario en reaccionar. Creé una función usando useState, para capturar los datos de mis entradas, luego otra función para mi formulario. Pero resulta que cuando hago clic en mi botón en mi formulario, los datos se envían el doble, ¿qué puedo hacer?
La función de mi formulario es así.
const handleSubmit = (evt)=>{ evt.preventDefault(); let respond = FormValidation(inputValues); if (respond.message) { setError(respond) }else{ auth.signUp(inputValues); } } const signUp = (author) =>{ setLoading(true) const {usuario, email, contraseña} = author const obj_author = { nombre : usuario, email : email, contrasenna : contraseña } console.log(obj_author); //Here the console shows me the data twice axios.post(API_ROUTE, obj_author,{ method : 'POST', headers : { "Content-type":'application/json' } }).then((res)=>{ setLoading(false) setAuth(obj_author) setIsLogin(true) console.log(res.data); }).catch((err)=>{ setLoading(false) setError(err) }) }La función de mis entradas es esta.
const handleChange = (evt)=>{ evt.preventDefault(); const input = evt.target const value = input.type === 'checkbox' ? input.checked : input.value setInputValues({ ...inputValues, [input.name] : value }) };