How can I api useQuery when calling a function?
const { data: allData, isLoading } = api.admin.limitAccess.useQuery(
{first,rows},
{ refetchOnWindowFocus: false }I am using useQuery to fetch first , rows depends on a pagination but I have a button to click so I can download all the data from the query so I want to use it like this
const exportCSV = async () => {
try {
const response = await api.admin.limitAccess.useQuery({ first: 0, rows: totalRecords });
setAllData(response?.data);
tableRef?.current?.exportCSV();
} catch (error) {
console.error("Error exporting CSV:", error);
}
};but when I use something like this I get an error , why I cannot use the api inside a function ?
Error exporting CSV: Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app