blob: 6ac3d429fb3b9981cfc317282ac74ec69ad3f70d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
import useSWR from 'swr';
import { getAllComments } from '../../services/graphql';
import { SingleComment } from '../../types';
export type UseCommentsConfig = {
contentId?: string | number;
fallback?: SingleComment[];
};
/**
* Retrieve the comments of a page/article.
*
* @param {string | number} contentId - A page/article id.
* @returns {SingleComment[]|undefined}
*/
export const useComments = ({
contentId,
fallback,
}: UseCommentsConfig): SingleComment[] | undefined => {
const { data } = useSWR(contentId ? { contentId } : null, getAllComments);
return data ?? fallback;
};
|