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

173
Views
useEffect, useState and promises.. what to do

I'm having trouble at the moment of getting these values. First, I have a token that I have to retrieve via SecureStore, for these I do it with useState, then I have an async function called getData(id), this id is used to query an API. I have to do 3 of these calls to 3 diferent id's, the data I get from the API I passed it to state hook called qo.

I use the useEffect hook for the first render to get the token, after that the second useEffect, that reacts to the token state, I call the getData funcion, but when it renders, it only shows 1 result of the other.

Code

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]);

I tried different useState but it is not a good solution

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!