SupremeTechnopriest / react-idle-timer

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

Manual Trigger of events bypassing Timeout. #297

Open YasarArafathAli opened 2 years ago

YasarArafathAli commented 2 years ago

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

SupremeTechnopriest commented 2 years ago

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 commented 1 year ago

@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.