@replyke/core
Version:
Replyke: Build interactive apps with social features like comments, votes, feeds, user lists, notifications, and more.
28 lines • 1.09 kB
JavaScript
import { useCallback } from "react";
import useAxiosPrivate from "../../config/useAxiosPrivate";
import useProject from "../projects/useProject";
function useAddReaction() {
const axios = useAxiosPrivate();
const { projectId } = useProject();
const addReaction = useCallback(async (props) => {
const { targetType, targetId, reactionType } = props;
if (!targetId) {
throw new Error("No target ID provided");
}
if (!reactionType) {
throw new Error("No reaction type provided");
}
if (!projectId) {
throw new Error("No project specified");
}
// Determine endpoint based on targetType
const endpoint = targetType === "entity"
? `/${projectId}/entities/${targetId}/reactions`
: `/${projectId}/comments/${targetId}/reactions`;
const response = await axios.post(endpoint, { reactionType });
return response.data;
}, [axios, projectId]);
return addReaction;
}
export default useAddReaction;
//# sourceMappingURL=useAddReaction.js.map