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
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 useIdleRelevant 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