From d4595aa69823c2268473bd2fcd1298c8e9852114 Mon Sep 17 00:00:00 2001 From: stonek Date: Sun, 22 Oct 2023 14:58:55 +0300 Subject: [PATCH] [#455] add descriptions to hook useTimer, remove duplicate unmount effect from ShareButton --- apps/blog/src/components/ShareButton/ShareButton.tsx | 9 +-------- apps/blog/src/utils/hooks/useTimer.ts | 7 +++++++ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/apps/blog/src/components/ShareButton/ShareButton.tsx b/apps/blog/src/components/ShareButton/ShareButton.tsx index ad3c5561..18d4075c 100644 --- a/apps/blog/src/components/ShareButton/ShareButton.tsx +++ b/apps/blog/src/components/ShareButton/ShareButton.tsx @@ -1,6 +1,6 @@ 'use client' -import React, { useCallback, useEffect, useState } from 'react' +import React, { useCallback, useState } from 'react' import * as Popover from '@radix-ui/react-popover' import { useTimer } from '@/utils/hooks/useTimer' @@ -22,13 +22,6 @@ export const ShareButton = ({ shareData, tooltipContent }: { shareData: ShareDat } }, [startTimer, stopTimer, open]) - useEffect( - () => () => { - stopTimer() - }, - [stopTimer], - ) - /** * Handles the click event for the button. * If the browser does not support the share API, it will copy the text (url/text/title), otherwise it will open the share dialog. diff --git a/apps/blog/src/utils/hooks/useTimer.ts b/apps/blog/src/utils/hooks/useTimer.ts index 651358c2..39edd610 100644 --- a/apps/blog/src/utils/hooks/useTimer.ts +++ b/apps/blog/src/utils/hooks/useTimer.ts @@ -5,6 +5,13 @@ interface TimerFunctions { stopTimer: () => void } +/** + * Generates a timer hook that allows the user to start and stop a timer. + * + * @param {() => void} callback - The callback function to be executed when the timer completes. + * @param {number} delay - The delay in milliseconds before the timer executes the callback function. Default is 2000. + * @return {TimerFunctions} - An object containing the startTimer and stopTimer functions, which can be used to start and stop the timer respectively. + */ export function useTimer(callback: () => void, delay = 2000): TimerFunctions { const timerRef = useRef(null)