# Cannot update reactions on comments

**URL:** <https://forum.social.plus/t/cannot-update-reactions-on-comments/889>\
**Category:** TS SDK\
**Created:** [August 23, 2023, 2:25am UTC](https://forum.social.plus/t/cannot-update-reactions-on-comments/889 "2023-08-23T02:25:08Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![fabianr](https://avatars.discourse-cdn.com/v4/letter/f/e9a140/32.png) [@fabianr](https://forum.social.plus/u/fabianr)\
**Post date:** [August 23, 2023, 2:25am UTC](https://forum.social.plus/t/cannot-update-reactions-on-comments/889/1 "2023-08-23T02:25:08Z")

</div>

I’m adding and removing reactions to comments. But the subscription to the comments of a Post is not reacting after adding or removing an action.

I’m using this method:

```auto
CommentRepository.getComments(
        { referenceType: 'post', referenceId, parentId, limit: 10, sortBy: 'firstCreated' },
        setComments,
);

```

Is there a better way to subscribe to the reactions of a specific comment?

---

<div class="post-metadata">

**Author:** ![SocialPlus\_Support](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.social.plus/socialplus_support/32/798_2.png) [@SocialPlus\_Support](https://forum.social.plus/u/SocialPlus_Support)\
**Post date:** [August 23, 2023, 3:57am UTC](https://forum.social.plus/t/cannot-update-reactions-on-comments/889/2 "2023-08-23T03:57:08Z")

</div>

Hi @fabianr

Which platform and version are you using?

Amity Support

---

<div class="post-metadata">

**Author:** ![fabianr](https://avatars.discourse-cdn.com/v4/letter/f/e9a140/32.png) [@fabianr](https://forum.social.plus/u/fabianr)\
**Post date:** [August 23, 2023, 2:24pm UTC](https://forum.social.plus/t/cannot-update-reactions-on-comments/889/3 "2023-08-23T14:24:35Z")

</div>

I’m using React Native with Amity TS SDK

---

<div class="post-metadata">

**Author:** ![fabianr](https://avatars.discourse-cdn.com/v4/letter/f/e9a140/32.png) [@fabianr](https://forum.social.plus/u/fabianr)\
**Post date:** [August 24, 2023, 3:18am UTC](https://forum.social.plus/t/cannot-update-reactions-on-comments/889/4 "2023-08-24T03:18:44Z")

</div>

Do you have further information regarding this request?

---

<div class="post-metadata">

**Author:** ![SocialPlus\_Support](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.social.plus/socialplus_support/32/798_2.png) [@SocialPlus\_Support](https://forum.social.plus/u/SocialPlus_Support)\
**Post date:** [August 24, 2023, 7:46am UTC](https://forum.social.plus/t/cannot-update-reactions-on-comments/889/5 "2023-08-24T07:46:49Z")

</div>

We will require your sdk version as well, thank you.

---

<div class="post-metadata">

**Author:** ![fabianr](https://avatars.discourse-cdn.com/v4/letter/f/e9a140/32.png) [@fabianr](https://forum.social.plus/u/fabianr)\
**Post date:** [August 24, 2023, 1:47pm UTC](https://forum.social.plus/t/cannot-update-reactions-on-comments/889/6 "2023-08-24T13:47:05Z")

</div>

“@amityco/ts-sdk”: “^6.5.2”,

---

<div class="post-metadata">

**Author:** ![SocialPlus\_Support](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.social.plus/socialplus_support/32/798_2.png) [@SocialPlus\_Support](https://forum.social.plus/u/SocialPlus_Support)\
**Post date:** [August 29, 2023, 10:32am UTC](https://forum.social.plus/t/cannot-update-reactions-on-comments/889/7 "2023-08-29T10:32:02Z")

</div>

Hello, thank you for your patience. We are currently in touch with our engineering team and will promptly provide an update as soon as we receive one.

---

<div class="post-metadata">

**Author:** ![SocialPlus\_Support](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.social.plus/socialplus_support/32/798_2.png) [@SocialPlus\_Support](https://forum.social.plus/u/SocialPlus_Support)\
**Post date:** [August 30, 2023, 1:41pm UTC](https://forum.social.plus/t/cannot-update-reactions-on-comments/889/8 "2023-08-30T13:41:39Z")

</div>

Hello, could you pls check the sample code below, this should address the reaction problem:

```auto
import { CommentRepository, CommunityRepository, SubscriptionLevels, UserRepository, getCommunityTopic, getUserTopic, subscribeTopic } from '@amityco/ts-sdk';

const [communityObject, setCommunityObject] = useState<Amity.Community>()
  const [userObject, setUserObject] = useState<Amity.User>()
  const [commentCollection, setCommentCollection] =useState<Amity.LiveCollection<Amity.Comment<any>>>();

 const subscribeCommentTopic = (targetType: string) => {
    if (isSubscribed) return;
  
    if (targetType === 'user' && userObject) {
      const user = userObject as Amity.User; // use getUser to get user by targetId
      disposers.push(
        subscribeTopic(getUserTopic(user, SubscriptionLevels.COMMENT), () => {
          // use callback to handle errors with event subscription
        }),
      );
      isSubscribed = true;
      return;
    }
  
    if (targetType === 'community' && communityObject) {
      console.log('communityObject:', communityObject)
      const community = communityObject as Amity.Community; // use getCommunity to get community by targetId
      disposers.push(
        subscribeTopic(getCommunityTopic(community, SubscriptionLevels.COMMENT), () => {
          // use callback to handle errors with event subscription
        }),
      );
      isSubscribed = true;
    }
  };

  function getCommentsByPostId(postId: string) {
    const unsubscribe = CommentRepository.getComments(
      {
        dataTypes: { matchType: 'any', values: ['text', 'image'] },
        referenceId: postId,
        referenceType: 'post',
      },
      (data: Amity.LiveCollection<Amity.Comment<any>>) => {
        if (data.error) throw data.error;
        if (!data.loading) {
          setCommentCollection(data);
        }
      }
    );

  }
  useEffect(() => {
    if(communityObject || userObject){
    console.log('postDetail.targetType:', postDetail.targetType)
      subscribeCommentTopic(postDetail.targetType as string);
    }
 
  }, [communityObject,userObject])
  
  useEffect(() => {
// targetType and targetId will be inside post object that you want to subscribe
    if(targetType === 'community'){
      CommunityRepository.getCommunity(postDetail.targetId, ({data: community})=>{
        setCommunityObject(community)
      });
    }else if(targetType === 'user'){
      UserRepository.getUser(postDetail.targetId, ({data: user})=>{
        setUserObject(user)
      });
    }
    getCommentsByPostId(postDetail.postId);
  }, [targetId, targetType]);

```
