함수의 인자가
const search = ({ departure, destination }) => {}
이런 형태라면,
{departure: value1, destination: value2}
'구조 분해 할당해서 value1과 value2가 입력되는 형태구나'
바로 이해해야 한다.
fetch
fetch는 Promise 객체를 리턴한다.
fetch('https://koreanjson.com/posts/1'); // Promise 리턴
Promise 안에는 PromiseState와 PromiseResult가 있다.
PromiseResult 안에 우리가 원하는 데이터가 있다. 어떻게 꺼내쓰면 될까?
fetch('https://koreanjson.com/posts/1')
.then((res) => console.log(res)) // Response { ~~~ }
then도 Promise 객체를 리턴한다.
console만 찍었으므로 지금 PromiseResult는 undefined
fetch('https://koreanjson.com/posts/1')
.then((res) => res)
이렇게 해주면, PromiseResult는 Response
await fetch('https://koreanjson.com/posts/1');
await를 써주면 바로 Response 반환
await가 리턴하는 것은 해당 프로미스 객체의 PromiseResult 값
'부트캠프 > TIL' 카테고리의 다른 글
Day 43. [사용자 친화 웹]UI/UX( in 프론트엔드 ) (0) | 2023.02.15 |
---|---|
Section 2 회고 (0) | 2023.02.10 |
코드스테이츠 프론트엔드 부트캠프 Day 31. [HTTP/네트워크] (0) | 2023.01.30 |
코드스테이츠 프론트엔드 부트캠프 Day 31. REST API (0) | 2023.01.30 |
객체 지향 프로그래밍 (0) | 2023.01.30 |