Skip to content
WingoUI
ComponentsTemplatesDocsPricingAI agentsBlogChangelogContact
Components
Buttons & Actions
ButtonButton GroupCopy ButtonDelete ButtonTheme ToggleToggleToggle Group
Inputs
Avatar UploadCalendarCheckboxColor PickerComboboxCountry SelectCron PickerCurrency InputDate PickerDate Range PickerDate Time PickerDuration PickerEmail InputEmoji PickerFile UploadFilter BuilderInputInput GroupListboxMasked InputMention InputMonth PickerMulti SelectNumber InputOTP InputPassword InputPhone InputRadio GroupRatingSearch InputSegmented ControlSelectSignature PadSliderSwitchTag InputTextareaTime PickerTimezone SelectTree Select
Forms
Address InputBooking WidgetCSV ImportFieldForm WizardInline EditInvoice line itemsRich Text EditorSchema Builder
Navigation
Back To TopBounce SidebarBreadcrumbCommand MenuGlobal SearchGooey NavHook SidebarNav MenuNav TabsPaginationProximity SidebarScroll ProgressSidebarStepsTable Of ContentsTabsTopbarUser MenuWorkspace Switcher
Overlays
Alert DialogContext MenuDialogDrawerDropdown MenuFamily DrawerHover CardPopoverShare DialogSheetShortcuts DialogTooltipTour
Feedback
AlertBannerCookie ConsentEmoji ReactionEmpty StateNotification BellNotification CenterProgressRoute ProgressSetup ChecklistSkeletonSpinnerToast
Data Display
Approval FlowAvatarBadgeCalendar ViewCode BlockComment ThreadContact cardCountdownDescription ListDiff ViewerFile ListFile managerFolderGanttJSON ViewerKbdLog ViewerMarkdownPresenceSchedulerTagTimelineTree View
Tables & Lists
Audit LogData TableDeal PipelineEditable GridKanbanListMembers tablePermissions MatrixTableTask ListVirtual List
Charts & Stats
Animated CounterArea chartBar chartDonut chartFunnel chartGaugeGitHub ActivityHeatmap calendarLeaderboardLine chartRadar chartRadial barSparklineStat CardTrackerTrend badge
Layout
AccordionApp ShellCardCollapsibleDetail LayoutEntity HeaderPage HeaderScroll AreaSeparatorSettings LayoutSplit ViewToolbar
Media
Audio PlayerCarouselCSV ViewerDOCX EditorDOCX ViewerExcel ViewerFile SystemImage compareImage CropperImage GalleryImage LightboxLocation MapPDF ViewerPowerPoint ViewerQR CodeStep PlayerVideo Player
AI Kit
Agent Status CardChat MessageChat ThreadChat WidgetConversation ListFluid OrbGrid RevealMatrix OrbModel PickerPrompt InputReasoning IndicatorRule BuilderSuggestion ChipsTool Call TimelineUsage MeterVoice InputWorkflow Canvas
Text & Effects
Background PatternGravity LettersMarqueeTerminalText AnimateText Rotate
Mobile
Action SheetBottom Tab BarFABHaptic ButtonHero HeaderInstall PromptLarge Title HeaderNotification BannerOnboarding CarouselPicker WheelPull To RefreshSlide To ConfirmSticky CTA BarSwipe DeckSwipeable Tabs
Commerce
Cart drawerCategory pickerCheckout stepsCoupon inputFavorite buttonFilter panelListing cardListing gridOrder trackerPricePrice rangePricing tableProduct galleryQuantity stepperReviewsSeller card
Marketing Sections
App Download SectionBlog Cards SectionCTA SectionFAQ SectionFeature GridFeature ShowcaseHero SectionIntegrations SectionLogo CloudMarketing FooterMarketing HeaderMarketing SectionNewsletter SectionPricing SectionStats SectionSteps SectionTeam SectionTestimonials SectionTimeline SectionVideo Section
Blocks
Admin Dashboard PageAdmin ShellAI Chat PageAPI Keys PageAutomation Builder PageCheckout PageCRM Contact PageCRM Pipeline PageError PagesInbox PageInvoice PageKPI DashboardListing Detail PageLogin PageMarketplace Home PageMarketplace Search PageMarketplace ShellMobile App HomeOnboarding FlowOrder History PagePost Listing WizardPricing PageProfile PageRegister PageSettings PageUsers Admin Page
Templates
About PageAcademy PageAccessibility PageAffiliate PageAgency PageAI Product PageAppointment Booking PageBlog PageBlog Post PageBug Bounty PageCareers PageChangelog PageCommunity PageCompare PageContact PageCustomer Story PageCustomers PageDemo Booking PageDevelopers PageDocs Home PageDownload PageEnterprise PageEvents PageExperts PageFAQ PageFeature PageGlossary PageHelp Article PageHelp Center PageHome Services PageImpact PageIntegration Detail PageIntegrations PageJob Detail PageLanding PageLaunch PageLegal PageManifesto PagePortfolio PagePress PageProduct Tour PagePromo PageReal Estate PageReferral PageResearch Report PageRestaurant PageRoadmap PageROI Calculator PageSecurity PageSolutions PageStartups PageStatus PageStorefront PageSwitch PageTemplate Gallery PageTravel PageWaitlist PageYear in Review Page
Hooks & Utilities
AI ChatChart kitCommerceDate utilsFile exportFile typesFiltersForm validationHapticsInvoicingMotion presetsNavigationNumber formatRelative timeRomanian locationsSpreadsheetText matchTonesUIProvideruseClipboarduseConsentuseControllableStateuseCooldownuseDebounceuseKeyboardInsetuseLocaleuseLongPressuseMediaControlsuseMediaQueryuseOverflowItemsusePersistedStateuseScrollEdgesuseScrollStateuseSelectionuseShortcutuseStickToBottom
GalleryTheme

Hooks & Utilities

useCooldown

Hooks & Utilities

useCooldown React hook in TypeScript

useControllableStateuseDebounce
Live props
Options
seconds30s
autoStart
persistKey
  1. Home
  2. Components
  3. Hooks & Utilities
  4. useCooldown
Pro

useCooldown React hook in TypeScript

v1.0.0·Added in 1.0.0

A React cooldown timer hook for resend and retry buttons: wait N seconds before a code can be sent again, kept across reloads.

Press Resend code: the button locks and counts down (0:30, 0:29...) while the ring fills, then unlocks. Reload the page with a persist key and the wait continues where it was. Reset stops it at once. The label updates once a second, on the second.

useCooldown is a Pro React hook in the React hooks and utilities category, written in TypeScript for React 19. It installs as source with npx wingo-ui@latest add use-cooldown, together with usePersistedState.

Add to a project

Requirements: React 19, in Next.js (App Router or Pages), Vite or React Router. Installation guide · Next.js setup · Vite setup

npx wingo-ui@latest add use-cooldown

useCooldown is part of Pro, with 298 more Pro items: $8 a month or $150 once. 14-day refund before you download any Pro item. See plans

Usage

Import useCooldown from @/hooks/use-cooldown.

import { Button } from "@/components/ui/button"
import { useCooldown } from "@/hooks/use-cooldown"

export function ResendCode({ onResend }: { onResend: () => Promise<void> }) {
  const resend = useCooldown({ seconds: 30, autoStart: true, persistKey: "otp-resend" })

  return (
    <Button
      variant="link"
      disabled={resend.active}
      onClick={async () => {
        await onResend()
        resend.start()
      }}
    >
      {resend.active ? `Resend code in ${resend.label}` : "Resend code"}
    </Button>
  )
}

API

  • secondsdefault 30
    number

    Length of one wait in seconds. start(seconds) overrides it for a single wait (a longer lock after 3 failed attempts).

  • autoStartdefault false
    boolean

    Start waiting on mount, for screens that open right after a code was sent (check your email, enter the SMS code). The server and hydration render the full wait, so the label never jumps.

  • persistKeydefault ""
    string

    Keeps the end time in local storage under this key, so a reload does not unlock the button early. Empty keeps it in memory.

  • onEnd
    () => void

    Runs once when a wait reaches zero (not on reset).

  • useCooldown
    (options?: UseCooldownOptions) => Cooldown

    Returns { remaining (whole seconds), active, endsAt, label ("0:42"), progress (0 to 1 for a ring), start(seconds?), reset() }. It ticks with one timeout per second aligned to the end time: one re-render a second, exact after the tab sleeps.

Parts

  • formatCooldown

    function

    Minutes and zero-padded seconds: 42 is "0:42", 65 is "1:05". Signature: (seconds: number) => string.

  • UseCooldownOptions

    type

    The options object: { seconds?: number; autoStart?: boolean; persistKey?: string; onEnd?: () => void }.

  • Cooldown

    type

    The return value: remaining, active, endsAt, label, progress, start(seconds?) and reset().

Examples

Starts on mount

The screen opens right after the code was sent.

Survives a reload

persistKey keeps the end time in local storage; reload mid-wait.

Inline link

A 15 second wait on a link under a form.

Dependencies

use-persisted-state

Files

  • hooks/use-cooldown.ts

FAQ

Is the useCooldown hook free?

The preview, props and docs are free; copying the source needs a Pro plan. See plans.

How do I install useCooldown?

Run npx wingo-ui@latest add use-cooldown. It also adds the Wingo UI item it builds on (usePersistedState). With shadcn, add the @wingo-ui registry with your API key, then run npx shadcn@latest add @wingo-ui/use-cooldown.

See also

OTP InputCountdownusePersistedStatehookButton

Used in

Login PageError PagesRegister PageSettings Page

More React hooks and utilities

useDebouncehookuseKeyboardInsethookuseLocalehookuseLongPresshookuseMediaControlshookuseMediaQueryhook
All 36 React hooks and utilities

Articles using this component

  • React OTP Input: Paste, SMS Autofill and a Resend Timer

    Component guides · Oct 9, 2026 · 11 min read

PrevioususeControllableStateNext useDebounce

Check your phone

We sent a 6 digit code to (555) 123-4567.

You can resend the code

remaining=0 active=false persistKey=""