Skip to content

🐞 Reset Method Increases the Original Timeout Temporarily #387

@zmikeska

Description

@zmikeska

What happened?

Calling reset within the onIdle makes it take more the amount of the original timeout to Idle. It seems to correct itself after a few iterations.

Reproduction Steps

Reference the below code and it will successfully Idle and the subsequent Idle will take longer to trigger.

import { forEach } from "lodash"
import { Dispatch, SetStateAction, useCallback, useRef } from "react"
import { IIdleTimer, useIdleTimer } from "react-idle-timer"

function useIdle() 
{
  const idleTimer = useRef<IIdleTimer>()

  const onAction = useCallback(() => {
    console.log('onAction')
  },[])

  const onIdle = useCallback(() => {
    console.log('onIdle')
      onAction()
      idleTimer.current?.reset())
  },[onAction])
  
  idleTimer.current = useIdleTimer({
    timeout: 1000 * 1 * 10,
    onIdle: onIdle,
    onAction : onAction,
    throttle: 1000 * 3
  })

  return {setNeverTimeout, setHasToken, setShouldExtend}
}

export default useIdle

Relevant log output

No response

Screenshots or Additional Context

No response

Module Version

5.7.2

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

Chrome, Microsoft Edge

What devices are you seeing the problem on?

Desktop

Verification

  • I have checked for existing closed issues and discussions.

Metadata

Metadata

Labels

bugA verified and reproducible bug.triageHas not been reviewed yet and should not be worked on.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions