I am using react-query to fetch data into react-table, but everytime I get the "TypeError: Cannot read property 'forEach' of undefined" error. The only way I can fix it is using "data" into the react-query "initialData" option, is there another way to fix this error?
const TableCompras = () => {
const data = [
{
nf: null,
fornecedor: null,
pagamento: null,
valorTotal: null
}
];
// Fetch Compras
const { data: compras, error, isLoading } = useQuery(
"compras", getAllCompras
, {
initialData: data
}
);
// React Table
const {
getTableProps,
getTableBodyProps,
headerGroups,
page,
nextPage,
previousPage,
canNextPage,
canPreviousPage,
pageOptions,
prepareRow,
state,
setGlobalFilter
} = useTable(
{
columns,
data: compras,
initialState: { pageSize: 5 }
},
useGlobalFilter,
useSortBy,
usePagination
);
}