Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

Studyyyyy

Promise.allSettled에서 result.value가 undefined로 나오는 오류 본문

자바스크립트, 타입스크립트

Promise.allSettled에서 result.value가 undefined로 나오는 오류

manyYun 2024. 8. 19. 08:37

https://stackoverflow.com/questions/53412109/fetch-returns-undefined-when-imported

 

Fetch returns undefined when imported

I have a function that fetches data from the url and is supposed to return it: const fetchTableData = () => { fetch('https://api.myjson.com/bins/15psn9') .then(result => result.json()) ...

stackoverflow.com

함수 안에서 fetch자체를 한번 더 return 해줘야한다.

 

ex)

잘못된 예시

const fetchTableData = () => {
fetch('https://api.myjson.com/bins/15psn9')
    .then(result => result.json())
    .then(data => {
        return data;
    })
}

export default fetchTableData;

 

올바른 예시

const fetchTableData = () => {
  const fetchedData = fetch('https://api.myjson.com/bins/15psn9')
    .then(result => result.json())
    .then(data => {
        return data;
    })

    return fetchedData;
}

export default fetchTableData;

 

 

슬랙에 올려논 글들이 1년이 넘어 지워지기 전에 정리중