useShowFastIconHint.ts
1 import { useEffect, useState } from 'react' 2 3 const HINT_DISPLAY_DURATION_MS = 5000 4 5 let hasShownThisSession = false 6 7 /** 8 * Hook to manage the /fast hint display next to the fast icon. 9 * Shows the hint for 5 seconds once per session. 10 */ 11 export function useShowFastIconHint(showFastIcon: boolean): boolean { 12 const [showHint, setShowHint] = useState(false) 13 14 useEffect(() => { 15 if (hasShownThisSession || !showFastIcon) { 16 return 17 } 18 19 hasShownThisSession = true 20 setShowHint(true) 21 22 const timer = setTimeout(setShowHint, HINT_DISPLAY_DURATION_MS, false) 23 24 return () => { 25 clearTimeout(timer) 26 setShowHint(false) 27 } 28 }, [showFastIcon]) 29 30 return showHint 31 }