SupremeTechnopriest / react-idle-timer

User activity timer component
https://idletimer.dev
MIT License
1.15k stars 143 forks source link

Need a timeout setting for the state is changing from `Idle` to `Active` #348

Open alexya opened 1 year ago

alexya commented 1 year ago

Feature Information

Is your feature request related to a problem? Please describe.

  const { getRemainingTime } = useIdleTimer({
    onIdle,
    onActive,
    onAction,
    timeout: 10_000, // timeout setting when state changing from `Active` to `Idle`
    throttle: 1500
  })

We will develop a web app that will charge the money from our customers according to the app usage time.

When the user starts to use the app, we charge the money. When the app is idle, it means that the user is leaving the browser/computer, etc., so we will not charge the money. And then when the app is active, it means that the user is back, and we will continue to start charging the money.

But the problem is that, when the user is back, the state is changing from idle to active immediately, and there is no cache. If the user just goes back to the tab and wants to close it, it will still trigger the onActive, and the user will be charged the money.

Describe the solution you'd like.

if the state is changing from Active to 'Idle, there is a timeout setting and getRemainingTime API for use, I wonder if you can add an optional parameter, a similar timeout setting, and API for the state changing fromidle` to 'Active'.

Describe alternatives you've considered.

Now, we have to use an additional code, e.g. setTimeout, to handle this scenario.

Additional context.

Add any other context or screenshots about the feature request here.