hasMore stale after dataUpdated event

I’m retrieving posts from a community and checking for further pages when the results are loaded using the following code.

import { FeedType, PostRepository } from '@amityco/js-sdk'

const communityId = 'XXX'

const results = PostRepository.queryCommunityPosts({
    feedType: FeedType.Published
    communityId,
})

results.on('dataUpdated', (data) => {
    console.log(results.hasMore)
    setTimeout(() => console.log(results.hasMore))
})

The problem is that the value of hasMore is always stale, and I need to work around this by wrapping the check in a setTimeout to get the correct value.

Given a community with two pages of results, the first load will return false for hasMore and if I call nextPage, the next load will return true.

Am I misunderstanding how to use the results? Or is this a bug?

Hi @matt - we have identified and is able to reproduce the issue. I have provide this bug to the product team and will fix it in the upcoming releases

1 Like

Hello @matt sorry for keeping you waiting, the fix version of this issue will be v4.18.0 which will be released on the 28th of September.

I use "@amityco/js-sdk": "^5.8.1" and it still reproduced for PostRepository.queryPosts method.

Hi @rdmitrij - can I confirm that the code is still the same as what you’ve shared a while ago?

It’s not a my code snippet, but yes, code is the same.

I updated the code snippet to this one and result the same.

import { PostRepository } from '@amityco/js-sdk';

const results = PostRepository.queryPosts({
    targetId: 'XXX',
    targetType: 'community',
    dataTypes: ['XXXX'],
})

results.on('dataUpdated', (data) => {
    console.log(results.hasMore); // false
    setTimeout(() => console.log(results.hasMore)); // true
});

could you please add limit: 5 into the query json?

Yes. Result is the same. I got false and then true

Hi @rdmitrij - sorry for the delayed response, I can confirm that this is currently a limitation of the system due to internal reactivity state. For now you will need to use setTimeout to help ‘tick’ the system

1 Like