Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created December 21, 2020 22:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/12006006865253e6f0e0766457bc1e8c to your computer and use it in GitHub Desktop.
Save parzibyte/12006006865253e6f0e0766457bc1e8c to your computer and use it in GitHub Desktop.
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