I am working on a React JS project that is using React query, https://react-query.tanstack.com/, React hooks and functional components. But it is throwing error when I use react query for API call.
This is my component and how I use query within it.
const App = () => {
const [ list, updateList ] = useState([])
const info = useQuery(["item-list"], getList, {
retry: false,
refetchOnWindowFocus: false,
})
if (info.status == "success") {
updateList(info.data)
}
return (
//view components here
)
}
This is my getList API call logic
export const getList= async () => {
const { data } = await api.get("8143487a-3f2a-43ba-b9d4-63004c4e43ea");
return data;
}
When I run my code, I get the following error:
react-dom.development.js:14815 Uncaught Error: Too many re-renders. React limits the number of renders to prevent an infinite loop.
What is wrong with my code?