본문 바로가기
에러 해결

[React-Query]error: Missing queryFn error when using useQuery

by codnjs779 2022. 4. 25.

리액트 쿼리 기능에서 useQuery를 사용할 때 두 번째 인자에 함수를 넣어줘야 하는데 이때 즉시 실행하는 함수 형태로 넣어주지 않으면 에러가 발생한다. 

 

stack overflow에서 같은 원인으로 발생한 문제를 올려둔 글이 있어 해당 답변을 통해 에러를 해결했다. 

https://stackoverflow.com/questions/70319827/missing-queryfn-error-when-using-usequery

 

Missing queryFn error when using useQuery

As the title suggests, I am new to using useQuery and the associated libraries, I am trying to use it to fetch data and then populates a list of fields that I have created However when I run it I get

stackoverflow.com

useQuery('monster', fetchMonster(props.slug))
//위와 같은 코드를 

useQuery('monster', () => fetchMonster(props.slug))
// 수정!