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

Issue when resetting timer🐞 #378

Open
1 task done
leahyjulian opened this issue Nov 30, 2023 · 0 comments
Open
1 task done

Issue when resetting timer🐞 #378

leahyjulian opened this issue Nov 30, 2023 · 0 comments
Assignees
Labels
bug A verified and reproducible bug. triage Has not been reviewed yet and should not be worked on.

Comments

@leahyjulian
Copy link

What happened?

When resetting the timer it appears to reset correctly when tracking remaining time, however the timeout value doubles before onIdle is called again

Reproduction Steps

1. set a timeout for 10 seconds
2. increase a count var every time idle is called 
3. reset timer
4. After first 10 seconds counter increase by 1 as expected
5. next time counter does not increase again for 20 seconds
6. New timeout appears to have doubled

Relevant log output

No response

Screenshots or Additional Context

sandbox

import { useIdleTimer } from "react-idle-timer";
import { useEffect, useState } from "react";

export default function App() {
  const [remaining, setRemaining] = useState(0);
  const [count, setCount] = useState(0);

 // correct behaviour first time onIdle is called
 // after reset onIdle is called every 20 seconds instead of 10
  const onIdle = () => {
    setCount((prev) => (prev += 1));
    reset();
  };

  const { reset, getRemainingTime } = useIdleTimer({
    onIdle,
    timeout: 10_000,
    throttle: 500,
  });

  useEffect(() => {
    const interval = setInterval(() => {
      setRemaining(Math.ceil(getRemainingTime() / 1000));
    }, 500);

    return () => {
      clearInterval(interval);
    };
  });
  return (
    <div className="App">
      <h1>Reset</h1>
      <h2>Time Remaining {remaining}</h2>
      <h2>Count: {count}</h2>
    </div>
  );
}

Module Version

5.7.2

What browsers are you seeing the problem on? Select all that apply.

Chrome

What devices are you seeing the problem on?

Desktop

Verification

  • I have checked for existing closed issues and discussions.
@leahyjulian leahyjulian added bug A verified and reproducible bug. triage Has not been reviewed yet and should not be worked on. labels Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A verified and reproducible bug. triage Has not been reviewed yet and should not be worked on.
Projects
None yet
Development

No branches or pull requests

2 participants