HI,
I am fetching user’s post on user page. I am using PostRepository.getPosts
with subscribePostTopic for live object implementation.
Here is my code:
useEffect(() => {
if (user) {
const targetType = 'user';
const targetId = user.userId;
const unsubscribe = PostRepository.getPosts(
{ targetId, targetType, limit: 20, sortBy: 'lastCreated' },
({ data: posts, onNextPage, hasNextPage, loading }) => {
setLoading(loading);
if (hasNextPage) {
setHasMoreData(true);
} else {
setHasMoreData(false);
}
setPosts(posts);
subscribePostTopic(targetType, user as any);
}
);
disposerPosts.push(unsubscribe);
return () => {
disposerPosts.forEach((fn) => fn());
};
}
}, [user, userId]);
Please suggest me a way to implement onNextPage when user scroll down to the page.
How can i access onNextPage function outside useeffect? or suggest me some other way to implement this.