I am making a GraphQL query to load Data in my Material UI table. I want it to load more data on scrolling.
The data is populated in the table correctly, the pagination stuff is not working correctly.
return (
<Query
query={MESSAGE_QUERY}
variables={{
where: getQueryVariables({
date,
}),
limit: 50,
offset: 0,
sortingOrder,
}}
fetchPolicy="cache-and-network"
>
{({ data, fetchMore }: QueryResult) => {
fetchMore({
variables: {
offset: data.message
? data.message.length
: 0,
},
updateQuery: (
prevResult: { DataRowProps: any },
{ fetchMoreResult }: any,
) => {
if (!fetchMoreResult) return prevResult;
return Object.assign({}, prevResult, {
...fetchMoreResult.DataRowProps,
});
},
});
return data.message
? data.message.map(
(rowData: DataRowProps, index: number) => {
return containmentDOMRect ? (
<VisibilitySensor
containment={containmentDOMRect.current || undefined}
onChange={isVisible =>
isVisible && index % LOAD_SIZE === 0 && index >= LOAD_SIZE
? loadMoreData(index)
: undefined
}
>
<DataRowComponent
{...rowData}
index={index}
selectedRow={selectedRow}
callBack={callBack}
/>
</VisibilitySensor>
) : null;
},
)
: null;
}}
</Query>
);
};
I don't see any errors while running the code but it is not loading more data on scroll. I have removed some unimportant code because the stack overflow restrictions, let me know if that needs to be provided. Any help is highly appreciated.