You may follow this sample steps in creating a simple text post and using the post to interact with the object in UI.
Create a text post using the sample code provided in the Create a Text Post section in this page.
Retrieve the post with the postId
that you'll get from the liveFeed object after creating the post.
useEffect(() => {
const liveFeed = PostRepository.queryUserPosts({
userId: client.currentUserId,
includeChildrenPosts: true,
includeDeletedPosts: false,
sortBy: PostSortingMethod.FirstCreated, // see PostSortingMethod
useExperimental: true, // to use v2 query (without sorting on SDK side, just keep order as received from back-end)
tags: ['tag1', 'tag2'],
});
liveFeed.once('dataUpdated', posts => {
console.log(posts.map(post => post))
setPosts(posts.map(post => ({
postId: post.postId,
postDataText: post.data.text,
reactionCount: post.reactionsCount
})))
});
}, [deletePost, handleSubmit, addReaction, removeReaction])
Use this post to interact with the object in the UI.
onClick={() => removeReaction(post.postId)}
Trigger useEffect
hook based on the user actions with a callBack async function and state hook.
const [isLiking, setIsLiking] = useState(false)
const addReaction = useCallback(async (postid) => {
if (isLiking) return
setIsLiking(true)
await PostRepository.addReaction({
postId: postid,
reactionName: 'like',
})
setIsLiking(false)
}, [isLiking])