728x90
    
    
  
Query data cannot be undefined 에러 발생 이유

useQuery에 등록한 함수가 Promise를 반환하지 않아서 발생
👉 호출만 하고 리턴을 안 했을 수 있음 아래 코드처럼
const { data, status} = useQuery(['videos', keyword], () => {
    youtube.search(keyword)
});
해결방법
Promise를 반환해주면됨
화살표함수로 바로 리턴하거나, 중괄호 내부에서 return을 적어주면 됨
1. 화살표함수로 바로리턴
const { data, status} = useQuery(['videos', keyword], () => 
    youtube.search(keyword)
);
2. 중괄호 내부에서 return
const { data, status} = useQuery(['videos', keyword], () => {
    return youtube.search(keyword)
});728x90
    
    
  'TIL' 카테고리의 다른 글
| 147. [CS] RESTfull API TIL23.04.06 (0) | 2023.04.06 | 
|---|---|
| 146. [JavaScript] this의 4가지 동작 방식 TIL23.04.04 (0) | 2023.04.05 | 
| 144. [React] react-query useQuery, useMutation 사용처 TIL 23.03.28 (0) | 2023.03.28 | 
| 143. [React] cashe(캐시)란? TIL 23.03.15 (0) | 2023.03.15 | 
| 142. [React] useNavigate로 state 넘기기 TIL23.03.14 (0) | 2023.03.14 | 
 
										
									 
										
									 
										
									 
										
									
댓글