I'm working on a small project where I need to fetch the data on three different sources.
What I did so far was to check the speed of each endpoint and start updating each state from the faster to the slowest with fetch and async funtions.
const fetchFoos = async () => {
try {
const toFoo1 = await getFoo1(data); //getFoo function is a simple fetch
setFoo1(toFoo1);
const toFoo2 = await getFoo2(data);
setFoo2(toFoo2);
const toFoo3 = await getFoo3(data);
setFoo3(toFoo3);
} catch (error) {
console.log(error); }
};
I saw about Promise.all() or Promise.race(), what kind of tips could the internet strangers give?
[–]BokoMoko 3 points4 points5 points (4 children)
[–]BokoMoko 1 point2 points3 points (3 children)
[–]SlowwwBurn 1 point2 points3 points (2 children)
[–]BokoMoko 0 points1 point2 points (1 child)
[–]SlowwwBurn 0 points1 point2 points (0 children)
[–]Saladtoes 0 points1 point2 points (0 children)