Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

164
Views
¿Cómo devuelvo un elemento de una función asíncrona?

He estado investigando para intentar obtener información de sitios web usando fetch. Probar async/await fue mi primera solución, y hasta ahora ha ido bien. Obtener la información que necesitaba fue pan comido, pero tratar de recuperar esos datos en main es mi problema. Los datos constantes en mi función principal, incluso con la etiqueta de espera, solo devuelven un objeto indefinido. ¿Cómo puedo obtener los datos que tengo en la función en mi principal?

 import React from "react"; import { WASTEMANAGEMENT_USERNAME, WASTEMANAGEMENT_PASSWORD, WASTEMANAGEMENT_APIKEY_AUTH, WASTEMANAGEMENT_APIKEY_CUSTID, WASTEMANAGEMENT_APIKEY_DATA, } from "@env"; async function login() { let response = await fetch("https://rest-api.wm.com/user/authenticate", { method: "POST", headers: { "content-type": "application/json", apikey: WASTEMANAGEMENT_APIKEY_AUTH, }, body: JSON.stringify({ username: WASTEMANAGEMENT_USERNAME, password: WASTEMANAGEMENT_PASSWORD, locale: "en_US", }), }); let res = await response.json(); const id = res.data.id; const access_token = res.data.access_token; response = await fetch( `https://rest-api.wm.com/authorize/user/${id}/accounts?lang=en_US`, { method: "GET", headers: { oktatoken: access_token, apikey: WASTEMANAGEMENT_APIKEY_CUSTID, }, } ); res = await response.json(); const custId = res.data.linkedAccounts[0].custAccountId; response = await fetch( `https://rest-api.wm.com/account/${custId}/invoice?userId=${id}`, { method: "GET", headers: { apikey: WASTEMANAGEMENT_APIKEY_DATA, token: access_token, }, } ); res = await response.json(); res.body.balances.filter((item) => { if (item.type === "Current") { console.log(item); return item; } }); } const WasteManagementLogin = async () => { const data = await login(); console.log(data); }; export default WasteManagementLogin;
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!