![[React] getFetch 커스텀 훅 hook 만들기](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2Fb7C1i9%2FbtsHLW3sKm1%2FRu3W786evAhOu5ZrJuxrj1%2Fimg.png)
💜 프로젝트 구현2024. 6. 3. 23:31[React] getFetch 커스텀 훅 hook 만들기
시작하기 앞서...React 에서 get 요청을 할 때, 로딩여부인 isLoading, 에러 객체 정보가 저장된 loadError, 데이터를 로드하는 함수인 handleLoad 를 반환하는 useFetch 라는 커스텀 훅을 만들어 사용하였다.import { useState } from 'react';const useFetch = (getData) => { const [isLoading, setIsLoading] = useState(false); const [loadError, setLoadError] = useState(null); const handleLoad = async (...arg) => { try { setLoadError(null); setIsLoading(tr..