react-idle-timer icon indicating copy to clipboard operation
react-idle-timer copied to clipboard

Manual Trigger of events bypassing Timeout.

Open YasarArafathAli opened this issue 2 years ago • 2 comments

Feature Information

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

I was working on a use case where the user FocusOuts from an editor, i want the idletimer to trigger onIdle event.

Describe the solution you'd like.

add a method to trigger events provided in the init of idle timer

YasarArafathAli avatar Nov 09 '22 08:11 YasarArafathAli

Have you checked out the [immediateEvents](https://idletimer.dev/docs/api/props#immediateevents) option? That might work for you.

Otherwise, what is stopping you from just calling your onIdle function? Something like:

const elementRef = useRef()

const onIdle = () => {
  if (!isIdle()) pause()
  // Do other stuff
}

const { isIdle, pause } = useIdleTimer({
  onIdle
})

useEffect(() => {
  elementRef.current.addEventListener('blur', handleIdle)
  return () => {
    elementRef.current.removeEventListener('blur', handleIdle)
  }
}, [])

SupremeTechnopriest avatar Nov 09 '22 19:11 SupremeTechnopriest

@YasarArafathAli

Just checking to see if this is still an issue for you. Would like to understand the use case a little better to craft the best solution.

SupremeTechnopriest avatar Dec 27 '22 04:12 SupremeTechnopriest