Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: React Flip Clock is not updating correctly in inactive tab #17

Closed
Kostanios opened this issue Apr 24, 2024 · 4 comments
Closed

Comments

@Kostanios
Copy link

The component gets derailed if you switch to another tab, the problem is solved if you perform force render after visibilitychange event. But it would be cool to add something like this out of the box

@sLeeNguyen
Copy link
Owner

could you provide a code example?

@Kostanios
Copy link
Author

could you provide a code example?

Looks not perfect, but with force render timer works better due browser tabs switch:

import { useEffect, useState } from "react";
import FlipClockCountdown from "@leenguyen/react-flip-clock-countdown";

export default function CustomFlipClockCountdown({ className, onComplete, to, labels }) {
const [_, forceRender] = useState({});

useEffect(() => {
    const forceUpdate = () => forceRender({});
    document.addEventListener("visibilitychange", forceUpdate);

    return () => document.removeEventListener("visibilitychange", forceUpdate);
}, []);

return <FlipClockCountdown key={_} className={className} onComplete={onComplete} to={to} labels={labels} />;

}

@sLeeNguyen
Copy link
Owner

@Kostanios
Sorry. I mean the code to reproduce this issue

@sLeeNguyen
Copy link
Owner

Ah. No worries. I've just understood your issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants