@replyke/core
Version:
Replyke: Build interactive apps with social features like comments, votes, feeds, user lists, notifications, and more.
39 lines • 1.49 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = require("react");
const useProject_1 = __importDefault(require("../projects/useProject"));
const axios_1 = __importDefault(require("../../config/axios"));
function useFetchEntityReactions() {
const { projectId } = (0, useProject_1.default)();
const fetchEntityReactions = (0, react_1.useCallback)(async (props) => {
const { entityId, page, limit = 20, reactionType, sortDir = "desc" } = props;
if (page === 0) {
throw new Error("Can't fetch reactions with page 0");
}
if (limit === 0) {
throw new Error("Can't fetch with limit 0");
}
if (!projectId) {
throw new Error("No project specified");
}
if (!entityId) {
throw new Error("No entity ID provided");
}
const params = {
page,
limit,
sortDir,
};
if (reactionType) {
params.reactionType = reactionType;
}
const response = await axios_1.default.get(`/${projectId}/entities/${entityId}/reactions`, { params });
return response.data;
}, [projectId]);
return fetchEntityReactions;
}
exports.default = useFetchEntityReactions;
//# sourceMappingURL=useFetchEntityReactions.js.map