Hi, I’m trying to build a paginated feed of all my posts. In the Amity console, I can see that I have 26 posts. However, I can’t get the query to return more than 20 ever:
const globalFeed = PostRepository.queryAllPosts({limit: 30});
globalFeed.on('dataUpdated', (posts) => {
console.log('All posts', posts);
setData(posts)
});
I’m using the "@amityco/js-sdk": "^5.35.3"
.
Even with the limit set to 30, I still get only 20 posts. Additionally, globalFeed.hasMore
is returning false, and calling globalFeed.nextPage()
manually via button press doesn’t return any additional posts.
How can I query all my posts?
For reference, here’s my entire feed component:
export default function Feed() {
const [data, setData] = useState([])
const [globalFeed, setGlobalFeed] = useState()
// setup global feed initially
useEffect(() => {
const globalFeed = PostRepository.queryAllPosts({limit: 30});
globalFeed.on('dataUpdated', (posts) => {
console.log('All posts', posts);
setData(posts)
});
setGlobalFeed(globalFeed)
}, [])
console.log(data)
const loading = globalFeed?.loadingStatus === LoadingStatus.Loading
return (
<InfiniteScroll
dataLength={data.length}
next={() => { globalFeed?.nextPage(); console.log("calling next page") }}
hasMore={globalFeed?.hasMore ?? true}
height={window.innerHeight - 80} // lil hack to enable pagination
>
{!loading && data.map((post) => (
<div key={post.postId}>
<FeedItem post={post} />
</div>
))}
<Button onClick={() => globalFeed?.nextPage()}> Load More </Button>
</InfiniteScroll>
)
}