import React, { useCallback, useEffect, useState } from "react"; type RedirectPageProps = { enableRedirectNowButton: boolean; }; const REDIRECT_DELAY_MS = 10000; const TARGET_URL = "https://hypershelf.demo.stf"; export function RedirectPage({ enableRedirectNowButton }: RedirectPageProps): JSX.Element { const [remainingMs, setRemainingMs] = useState(REDIRECT_DELAY_MS); useEffect(() => { const redirectTimeoutId = window.setTimeout(() => { window.location.assign(TARGET_URL); }, REDIRECT_DELAY_MS); const intervalId = window.setInterval(() => { setRemainingMs(previous => { const next = previous - 1000; if (next <= 0) { window.clearInterval(intervalId); return 0; } return next; }); }, 1000); return () => { window.clearTimeout(redirectTimeoutId); window.clearInterval(intervalId); }; }, []); const handleRedirectNow = useCallback((): void => { window.location.assign(TARGET_URL); }, []); const secondsRemaining = Math.ceil(remainingMs / 1000); return (

Hello

Redirecting to {TARGET_URL} in {secondsRemaining} seconds.

{enableRedirectNowButton && ( )}
); }