Answer the question
In order to leave comments, you need to log in
How to resolve a promise in another React component?
Hello, tell me where to dig?)) There is a function. In the function itself, if you write then, everything will resolve.
getData(startUrl).then((data) => {
let promises = [];
data.starships.forEach(starship => {
promises.push(getData(starship));
});
return Promise.all(promises);
});
const { getData } = useContext(ApiContext);
useEffect(() => {
getData().then(data => {
console.log('data: ', data);
}).catch(e => {
console.log(e);
})
}, [getData])
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question