@mohamedismael This might happen because this.liveFeed.on(‘dataUpdated’, posts in the useEffect is called before the post has finished the post creation. You can follow my code.
const [postObject, setPostObject] = useState()
const createPost =() => {
const livePost = PostRepository.createTextPost({
targetId: 'userId',
targetType: PostTargetType.UserFeed, // optional, max no.of tags = 5, max length per tag = 24 chars
text: 'Test post text',
});
livePost.once('dataUpdated', model => {
console.log('Post', model);
setPostObject(model)
})
}
const queryPost=()=>{
const liveFeed = PostRepository.queryUserPosts({
userId: 'userId',
includeChildrenPosts: true,
includeDeletedPosts: false,
sortBy: PostSortingMethod.FirstCreated, // see PostSortingMethod
});
liveFeed.once('dataUpdated', posts => {
console.log('this is post query',posts.map(post => post))
});
}
useEffect(() => {
queryPost()
}, [postObject])
From the code, I made the useEffect call the queryPost function after the post creation is finished, so after you call function createPost(), it will also call queryPost() without refreshing the page.
sorry but this not what i want
i use vuejs
and i need to refresh data when another user create a post not the current user
i will show you the scenario
1- load - PostRepository.queryAllPosts
2- subscribe to it on(‘dataUpdated’)
3- another user with different device add new post
4- the current user not see the post until he refresh the whole page and call client.registerSession({ userId })
Expected
user can refresh data and see another user post without refresh page and call client.registerSession again
i used vuejs not react
can you explain to me how to get updated data from database whiteout make register session again
Basically, the updated data can be gotten by calling again the query function. Try to avoid refreshing web page because this will end the user session, so that’s why you need to call client.registerSession({ userId }) again. The main reason that you’re not received updated data because you haven’t call query post function again yet after someone create a new post.
Therefore, my recommendation would be
1- load - PostRepository.queryAllPosts
2- subscribe to it on(‘dataUpdated’)
3- another user with different device add new post
4. Create button to trigger query post function and call query post function again ( repeat step 1 and 2)
For example in facebook , users get the updated post data when they click at the home tab button. This is one of the ideas that you can use to receive updated posts without refreshing the web page.