json-server의 정렬 기능

박찬호·2024년 1월 19일

이전 const response = await axios.get("http://localhost:3001/products");

이후 const response = await axios.get(
"http://localhost:3001/products?_sort=price&_order=desc"
);

장점
1. useEffect는 화면 렌더링 후 딱 한 번만 실행되게 통제 가능하다

→ ex) 데이터 요청 후 setState 실행할 때 **무한 렌더링 발생 방지**
  1. dependency array로 useEffect 실행 조건 추가 가능

    → ex) 버튼 클릭으로 정렬 데이터 가져오기 가능

profile
열심히 하자

0개의 댓글