mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 10:42:08 +00:00
Add custom hooks for time distance and retrieving like count
Documentation added to all custom hooks
This commit is contained in:
@@ -9,6 +9,17 @@ interface UseBeerPostCommentsProps {
|
||||
pageSize: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* A custom React hook that fetches comments for a specific beer post.
|
||||
*
|
||||
* @param props - The props object.
|
||||
* @param props.pageNum - The page number of the comments to fetch.
|
||||
* @param props.id - The ID of the beer post to fetch comments for.
|
||||
* @param props.pageSize - The number of comments to fetch per page.
|
||||
* @returns An object containing the fetched comments, the total number of comment pages,
|
||||
* a boolean indicating if the request is currently loading, and a function to mutate
|
||||
* the data.
|
||||
*/
|
||||
const useBeerPostComments = ({ pageNum, id, pageSize }: UseBeerPostCommentsProps) => {
|
||||
const { data, error, isLoading, mutate } = useSWR(
|
||||
`/api/beers/${id}/comments?page_num=${pageNum}&page_size=${pageSize}`,
|
||||
|
||||
Reference in New Issue
Block a user