-
Hi, export const ALL_DATA_QUERY = gql`
query allData($first: Int, $cursor: String) {
allData(sort: data1, first: $first, after: $cursor) {
pageInfo {
startCursor
endCursor
hasNextPage
hasPreviousPage
}
totalCount
edges {
node {
data1
}
}
}
}
`;
export default function OrderList() {
const { loading, error, orderData, fetchMore, networkStatus } = useQuery(ALL_ORDERS_QUERY, {
notifyOnNetworkStatusChange: true,
variables: allOrdersQueryVars,
});
const [data, setData] = useState([]);
const [pageCount, setPageCount] = React.useState(1)
const dataFetch = (nextCursor) => {
fetchMore({
query: ALL_DATA_QUERY,
notifyOnNetworkStatusChange: true,
variables: {
first: 10,
// cursor: data.allOrders.pageInfo.endCursor,
},
updateQuery: (previousResult, { fetchMoreResult }) => {
const newEdges = fetchMoreResult.allOrders.edges;
return fetchMoreResult
},
}).then(response => {
console.log("fetched!")
// console.log(response)
setData(response.data.allOrders.edges)
setPageCount(1)
})
};
const columns = React.useMemo(
() => [
{
Header: 'Everything',
columns: [
{
Header: 'First Name',
accessor: 'data1',
}
],
},
],
[]
)
return (
<DataTable
columns={columns}
data={data}
fetchData={dataFetch}
pageCount={1}
/> and Datatable: function OrderTable({
columns,
data,
fetchData,
loading,
pageCount: controlledPageCount,
}) {
const {
getTableProps, getTableBodyProps, headerGroups, prepareRow,
page, canPreviousPage,canNextPage, pageOptions, pageCount, gotoPage, nextPage,
previousPage, setPageSize,
state: { pageIndex, pageSize },
} = useTable(
{
columns,
data,
initialState: { pageIndex: 0 }, // Pass our hoisted table state
manualPagination: true, // Tell the usePagination
pageCount: controlledPageCount,
},
usePagination
)
React.useEffect(() => {
fetchData()
}, [fetchData, pageIndex, pageSize])
// Render the UI for your table
return (
<>
<table {...getTableProps()}>
...
</>
)
} it's going into infinite loop in:
I tried to use |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I ended up using lazy query.
|
Beta Was this translation helpful? Give feedback.
-
@pszafer are you implementing sorting when the user clicks on any particular column? |
Beta Was this translation helpful? Give feedback.
I ended up using lazy query.