/manejarEnvioDeFormulario.js Secret
Created
December 21, 2020 22:21
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async manejarEnvioDeFormulario(evento) { | |
evento.preventDefault(); | |
// Codificar nuestro videojuego como JSON | |
const cargaUtil = JSON.stringify(this.state.videojuego); | |
// ¡Y enviarlo! | |
const respuesta = await fetch(`${Constantes.RUTA_API}`, { | |
method: "POST", | |
body: cargaUtil, | |
headers: { | |
"Content-Type":"application/json", | |
} | |
}); | |
const exitoso = await respuesta.json(); | |
if (exitoso) { | |
toast('Videojuego guardado 🎮', { | |
position: "top-left", | |
autoClose: 2000, | |
hideProgressBar: false, | |
closeOnClick: true, | |
pauseOnHover: true, | |
draggable: true, | |
progress: undefined, | |
}); | |
this.setState({ | |
videojuego: { | |
nombre: "", | |
precio: "", | |
calificacion: "", | |
} | |
}); | |
} else { | |
toast.error("Error guardando. Intenta de nuevo"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment