Activity Timeout in milliseconds.
Props
Props are the configuration options that can be passed to useIdleTimer
or
withIdleTimer
. All props are optional and have sensible defaults. If a prop
is updated dynamically, IdleTimer will be automatically restarted with the new
set of properties. Examples of how they are used can be found in the
hook and
higher order component docs.
timeout#
number
1200000
promptTimeout#
When the user becomes idle, the onPrompt
and onPresenceChange
event handlers are called. After the prompt timeout in milliseconds is reached, the onIdle
and onPresenceChange
event handlers are called.
number
0
promptBeforeIdle
.promptBeforeIdle#
The amount of milliseconds before idle timeout to call the onPrompt and onPresenceChange event handlers.
number
0
events#
DOM events to watch for activity on.
EventsType[]
['mousemove','keydown','wheel','DOMMouseScroll','mousewheel','mousedown','touchstart','touchmove','MSPointerDown','MSPointerMove','visibilitychange']
immediateEvents#
DOM events that will bypass the timeout and immediately call onPrompt/onIdle. The events in this array take precedence over the events array.
EventsType[]
[]
onPresenceChange#
Function to call when the user's presence state changes. This provides a single function to handle all state changes. The IIdleTimer API is passed in as the second parameter.
(presence: PresenceType, idleTimer?: IIdleTimer) => void
() => {}
// The presence type definitiontype PresenceType = { type: 'idle' } | { type: 'active', prompted: boolean }
// Example onPresenceChange implementationimport type { PresenceType } from 'react-idle-timer'const onPresenceChange = (presence: PresenceType) => {const isIdle = presence.type === 'idle'const isActive = presence.type === 'active' && !presence.promptedconst isPrompted = presence.type === 'active' && presence.prompted}
onPrompt#
When promptTimeout
is set, this function is called after the user becomes idle. This is useful for displaying a confirmation prompt. If the prompt timeout is reached, onIdle
is then called. The IIdleTimer API is passed in as the second parameter.
(event?: Event, idleTimer?: IIdleTimer) => void
() => {}
onIdle#
Function to call when the user is idle. The IIdleTimer API is passed in as the second parameter.
(event?: Event, idleTimer?: IIdleTimer) => void
() => {}
onActive#
Function to call when the user becomes active. The IIdleTimer API is passed in as the second parameter.
(event?: Event, idleTimer?: IIdleTimer) => void
() => {}
onAction#
Function to call on user activity. The IIdleTimer API is passed in as the second parameter.
(event?: Event, idleTimer?: IIdleTimer) => void
() => {}
onMessage#
Function to call when a message
event is received. The IIdleTimer API is passed in as the second parameter.
(data: any, idleTimer?: IIdleTimer) => void
() => {}
debounce#
Debounce the onAction
function by setting delay in milliseconds.
number
0
throttle#
Throttle the onAction
function by setting delay in milliseconds.
number
0
eventsThrottle#
Throttle the activity events. Useful if you are listening to mouse events. Helps to cut down on CPU usage.
number
200
element#
Element to bind activity listeners to.
Node
document
startOnMount#
Start the timer when the hook mounts.
boolean
true
startManually#
Require the timer to be started manually.
boolean
false
stopOnIdle#
Once the user goes idle the IdleTimer will not reset on user input. Instead, `start()` or `reset()` must be called manually to restart the timer.
boolean
false
disabled#
Disables the timer. Disabling the timer resets the internal state. When the property is set to true (enabled), the timer will be restarted, respecting the startManually
property. If the timer is disabled, the control methods start
, reset
, activate
, pause
and resume
will not do anything.
boolean
false
timers#
Set custom timers. By default main thread timers are used to allow for better tree shaking. If you want to use worker thread timers, import them from the package and set them here.
ITimers
{ setTimeout, clearTimeout, setInterval, clearInterval }
crossTab#
Enable cross tab event replication.
boolean
false
name#
Sets the name for the IdleTimer instance. This is required if you are running multiple instances with crossTab
enabled.
string
idle-timer
syncTimers#
Syncs timers across all tabs. Timers are synced when user input is detected. The value of this property is the duration of the throttle on the sync operation. Setting to 0 disables the feature.
number
0
leaderElection#
Enables the Leader Election feature. Leader Election will assign one tab to be the leader. To determine if a tab is the leader, use the isLeader
method.
boolean
false