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

useIdle doesn't start tracking until after the first event #6682

Closed
2 tasks done
chimericdream opened this issue Aug 16, 2024 · 0 comments · Fixed by #6683
Closed
2 tasks done

useIdle doesn't start tracking until after the first event #6682

chimericdream opened this issue Aug 16, 2024 · 0 comments · Fixed by #6683

Comments

@chimericdream
Copy link
Contributor

Dependencies check up

  • I have verified that I use latest version of all @mantine/* packages

What version of @mantine/* packages do you have in package.json?

7.12.1

What package has an issue?

@mantine/hooks

What framework do you use?

Vite

In which browsers you can reproduce the issue?

All

Describe the bug

The useIdle hook does not start its timer until after the first event occurs. For example, with the code below, if there are no click or keypress events after the page loads, idle will never be true.

const idle = useIdle(5000, {
    initialState: false,
    events: ['click', 'keypress'],
});

I found one report of this in Discord, but it was posted in November 2023 and has no replies to the initial posting.

If possible, include a link to a codesandbox with a minimal reproduction

https://codesandbox.io/p/sandbox/useidle-mantine-bug-tx5znz?file=%2Fsrc%2FApp.tsx

Possible fix

Start the timer immediately in the useIdle hook instead of waiting for an event first.

Self-service

  • I would be willing to implement a fix for this issue
chimericdream pushed a commit to chimericdream/mantine that referenced this issue Aug 16, 2024
chimericdream pushed a commit to chimericdream/mantine that referenced this issue Aug 26, 2024
rtivital pushed a commit that referenced this issue Aug 26, 2024
…r did non interact with the page (#6683)

* [@mantine/hooks] use-idle: Start timer immediately instead of waiting for an event (#6682)

* [@mantine/hooks] use-idle: Fix test formatting (#6682)

---------

Co-authored-by: Bill Parrott <bill.parrott@prescryptive.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant