Skip to main content

Overview

useAddReaction is a low-level hook that adds a reaction to an entity or comment. For most use cases, use useReactionToggle instead — it handles toggling, optimistic updates, and state management automatically.
Requires an authenticated user.

Usage Example

import { useAddReaction } from "@replyke/react-js";

function UpvoteButton({ entityId }: { entityId: string }) {
  const addReaction = useAddReaction();

  const handleUpvote = async () => {
    await addReaction({
      targetType: "entity",
      targetId: entityId,
      reactionType: "upvote",
    });
  };

  return <button onClick={handleUpvote}>Upvote</button>;
}

Parameters

targetType
"entity" | "comment"
required
The type of the reaction target.
targetId
string
required
The ID of the entity or comment.
reactionType
ReactionType
required
The reaction to add: "upvote", "downvote", "like", "love", "wow", "sad", "angry", or "funny".

Returns

Entity | Comment
Entity | Comment
The updated entity or comment with new reactionCounts and userReaction.