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

171
Views
useEffect, useState y promesas... qué hacer

Estoy teniendo problemas en el momento de obtener estos valores. Primero, tengo un token que debo recuperar a través de SecureStore, para esto lo hago con useState , luego tengo una función asíncrona llamada getData(id) , esta identificación se usa para consultar una API . Tengo que hacer 3 de estas llamadas a 3 ID diferentes, los datos que obtengo de la API los pasé al enlace de estado llamado qo .

Utilizo el gancho useEffect para el primer procesamiento para obtener el token, después de eso, el segundo useEffect, que reacciona al estado del token, llamo a la función getData, pero cuando se procesa, solo muestra 1 resultado del otro.

Código

 const [st, onSt] = useState(""); const [qo, onQo] = useState([]); const getValue = async() => { let result = await SecureStore.getItemAsync("ST"); if (result) { onSt(result); } }; const getData = async(id) => { return fetch(`https: //URL.COM/api/card/${id}`, { method: "GET" }) .then((ans) => ans.json()) .then((json) => { const obje = json.result_metadata[0].fingerprint.type; const tip = obje["type/Number"]; onQo([ ...qo, { title: json.name, value: tipo.max, author: json.creator.common_name, }, ]); }) .catch((error) => console.log(error)); }; useEffect(() => { getValue(); }, []); useEffect(() => { getUser(); getData(2272); getData(2273); getData(2274); }, [st]);

Probé diferentes useState pero no es una buena solución

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!