@replyke/core
Version:
Replyke: Build interactive apps with social features like comments, votes, feeds, user lists, notifications, and more.
42 lines • 1.42 kB
JavaScript
import { useCallback } from "react";
import useProject from "../projects/useProject";
import useAxiosPrivate from "../../config/useAxiosPrivate";
function useFetchManyComments() {
const { projectId } = useProject();
const axios = useAxiosPrivate();
const fetchComments = useCallback(async (props) => {
const { entityId, userId, parentId, sortBy, page, limit, include, sourceId, } = props;
if (page === 0) {
throw new Error("Can't fetch comments with page 0");
}
if (limit === 0) {
throw new Error("Can't fetch with limit 0");
}
if (!projectId) {
throw new Error("No project specified");
}
const params = {
sortBy,
page,
limit,
};
if (entityId)
params.entityId = entityId;
if (userId)
params.userId = userId;
if (parentId)
params.parentId = parentId;
if (sourceId)
params.sourceId = sourceId;
if (include) {
params.include = Array.isArray(include) ? include.join(',') : include;
}
const response = await axios.get(`/${projectId}/comments`, {
params,
});
return response.data;
}, [projectId, axios]);
return fetchComments;
}
export default useFetchManyComments;
//# sourceMappingURL=useFetchManyComments.js.map