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.
Usage Example
Props
Whether the reaction target is an entity or a comment.
The ID of the entity or comment.
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.true while a toggle request is in flight. Prevents concurrent reactions.
