Overview
useReactionToggle is the recommended hook for reaction UIs. It manages the current reaction and reaction counts locally with optimistic updates, handles toggling (selecting the same reaction removes it), and reverts on error.
It works for both entities and comments via the targetType prop. For an entity, the server’s result also updates the entity’s userReaction and reactionCounts in every loaded entity list.
Usage Example
Props
The authenticated user’s current reaction, if any. Sourced from
entity.userReaction or comment.userReaction.The current reaction counts object. Sourced from
entity.reactionCounts or comment.reactionCounts.Return Values
The authenticated user’s current reaction. Updates optimistically on
toggleReaction.The current reaction counts. Updated optimistically and corrected from server response.
Toggles the given reaction. If the user already has this reaction, it is removed. If a different reaction is active, it is replaced. Returns the updated entity or comment from the server, or
null on error.
