fetch를 axios로 바꾸기

hanna·2023년 1월 17일
0

TIL

목록 보기
12/20

fetch

  const fetchComments = async (currentPage) => {
    const res = await fetch(
      `https://jsonplaceholder.typicode.com/comments?_page=${currentPage}&_limit=5`
    );
    const data = await res.json();
    return data;
  };

  const handlePageClick = async (data) => {
    console.log(data.selected);

    let currentPage = data.selected + 1;

    const commentsFormServer = await fetchComments(currentPage);
    
    setItems(commentsFormServer);
  };

axios

  const axiosPosts = async (currentPage) => {
    const res = await axios.get(
      `https://jsonplaceholder.typicode.com/comments?_page=${currentPage}&_limit=5`
    );
    const data = await res.data;
    return data;
  };

const handlePageClick = async (data) => {
    console.log(data.selected);

    let currentPage = data.selected + 1;

    const commentsFormServer = await axiosPosts(currentPage);
  
    setItems(commentsFormServer);
  };

0개의 댓글

관련 채용 정보