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