---
# System prepended metadata

title: C+ toggle reaction on comment - Thurs 17th Sept
tags: [C+, usersReactions, programmingjournal, '2020', reactions, bugs]

---

# C+ toggle reaction on comment - Thurs 17th Sept

I started implementing reacting to a **feed item** (rather than comment) functionality in C+. I decided to refactor my previous logic for reacting to a comment into a hook, so as to make my `<AddReaction />` component cleaner and easier to reason about, and also to reuse a lot of the functionality when reacting to a feed item.

This did, however, lead to a bug! The mutation for reacting was working properly, as was the logic for updating the reaction values in the cache.

The problem was in the logic that updated the UI showing whether you, the *current user*, had reacted to that comment. I was passing the previous, stale list of `usersReactions` to my update UI logic. This meant the current user reacted UI was always out of date.

In the end the fix was easy - simply use the updated `usersReactions` I got back from the mutation payload to update the UI! But it was a fun few hours of debugging before this solution was reached!

###### tags: `programmingjournal` `2020` `C+` `reactions` `usersReactions` `bugs`