Skip to content

Commit

Permalink
[#455] add descriptions to hook useTimer, remove duplicate unmount ef…
Browse files Browse the repository at this point in the history
…fect from ShareButton
  • Loading branch information
Stonek79 authored and Themezv committed Oct 26, 2023
1 parent 5036669 commit c6a7ec7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
9 changes: 1 addition & 8 deletions apps/blog/src/components/ShareButton/ShareButton.tsx
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions apps/blog/src/utils/hooks/useTimer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<NodeJS.Timeout | null>(null)

Expand Down

0 comments on commit c6a7ec7

Please sign in to comment.