Created
June 8, 2023 15:34
-
-
Save JajoScript/01b1576f80f492afd95419042407d54e to your computer and use it in GitHub Desktop.
Promise callback example
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 function getStudent(studentId){ | |
return new Promise(async (resolve, reject) => { | |
try { | |
// Consulta a la BD. | |
const data = await fecth("URL") | |
.then((response) => { | |
console.log("RESPONSE:", response) | |
response.json() | |
}) | |
.then((data) => { | |
console.log("DATA:", data) | |
return data; | |
}) | |
.catch((err) => { | |
console.error(err) | |
return null | |
}) | |
// Respuesta react-query | |
if (data) resolve(data) | |
resolve(null) | |
} catch (err) { | |
console.error(err) | |
reject(err) | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment