Skip to content

Instantly share code, notes, and snippets.

@JajoScript
Created June 8, 2023 15:34
Show Gist options
  • Save JajoScript/01b1576f80f492afd95419042407d54e to your computer and use it in GitHub Desktop.
Save JajoScript/01b1576f80f492afd95419042407d54e to your computer and use it in GitHub Desktop.
Promise callback example
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