All Projects → SupremeTechnopriest → React Idle Timer

SupremeTechnopriest / React Idle Timer

Licence: mit
User activity timer component

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Idle Timer

activity-timer
Activity timer powerup for Trello
Stars: ✭ 28 (-93.33%)
Mutual labels:  timer, activity
Wnr
⏱️ It's a time-management tool for computers. Work and rest, with wnr now.
Stars: ✭ 385 (-8.33%)
Mutual labels:  timer
Fliptimerview
FlipTimerView library for Android
Stars: ✭ 275 (-34.52%)
Mutual labels:  timer
Swoole Src
🚀 Coroutine-based concurrency library for PHP
Stars: ✭ 17,175 (+3989.29%)
Mutual labels:  timer
Atom Wakatime
Atom plugin for automatic time tracking and metrics generated from your programming activity.
Stars: ✭ 303 (-27.86%)
Mutual labels:  timer
Pvm
Build workflows, activities, BPMN like processes, or state machines with PVM.
Stars: ✭ 348 (-17.14%)
Mutual labels:  activity
Snaptimer
Implementation of Snapchat's stories timer.
Stars: ✭ 273 (-35%)
Mutual labels:  timer
Activitystarter
Simple Android Library, that provides easy way to start the Activities with arguments.
Stars: ✭ 414 (-1.43%)
Mutual labels:  activity
Keepalive
Fighting against force-stop kill process on Android with binder ioctl / Android高级保活
Stars: ✭ 376 (-10.48%)
Mutual labels:  activity
Timingwheel
Golang implementation of Hierarchical Timing Wheels.
Stars: ✭ 325 (-22.62%)
Mutual labels:  timer
Hauler
Library with swipe to dismiss Activity gesture implementation
Stars: ✭ 325 (-22.62%)
Mutual labels:  activity
Peaclock
A responsive and customizable clock, timer, and stopwatch for the terminal.
Stars: ✭ 314 (-25.24%)
Mutual labels:  timer
Github Activity Readme
Updates README with the recent GitHub activity of a user
Stars: ✭ 354 (-15.71%)
Mutual labels:  activity
Netserver
A C++ High Performance Net Library
Stars: ✭ 271 (-35.48%)
Mutual labels:  timer
Timerview
一个解耦良好的计时控件,可自由扩展。
Stars: ✭ 387 (-7.86%)
Mutual labels:  timer
Promise Timer
A trivial implementation of timeouts for Promises, built on top of ReactPHP.
Stars: ✭ 270 (-35.71%)
Mutual labels:  timer
Laravel S
LaravelS is an out-of-the-box adapter between Swoole and Laravel/Lumen.
Stars: ✭ 3,479 (+728.33%)
Mutual labels:  timer
Nutzmore
让Nutz更好用
Stars: ✭ 328 (-21.9%)
Mutual labels:  activity
Mob
Tool for swift git handover.
Stars: ✭ 418 (-0.48%)
Mutual labels:  timer
Libcopp
cross-platform coroutine library in c++
Stars: ✭ 398 (-5.24%)
Mutual labels:  timer

⏱ React Idle Timer

npm npm Tests Test Coverage Maintainability

JavaScript Style Guide

⚡️ Support for React 16
🚀 Support for Isomorphic React
🎣 Hook Implementation

Latest News

Version 4.5.0 adds user idle time tracking:

☝️ Added getTotalIdleTime() and getLastIdleTime() methods to track user idle timings.

Version 4.4.0 adds user active time tracking and reduces module size:

☝️ Added getTotalActiveTime() method to get the total milliseconds a user has been active for the current session.

✌️ Reduced NPM package size by excluding examples from downloaded module.

Version 4.3.0 adds a new hook implementation and some minor performance improvements:

☝️ The hook implementation is here! It takes the same properties and returns the same API as the component implementation. See here for usage or check out the new example. There are now TypeScript examples as well.

✌️ Added a new property called eventsThrottle. This will throttle the event handler to help decrease cpu usage on certain events (looking at you mousemove). It defaults to 200ms, but can be set however you see fit. To disable this feature, set it to 0.

For the full patch notes please refer to the CHANGELOG

Installation

yarn add react-idle-timer

or

npm install react-idle-timer --save

Examples

You can install the dependencies for all the examples by running:

npm run example-install

Component Usage

Run npm run example-component to build and run the component example. The example is a create-react-app project. IdleTimer is implemented in the App Component.

import React, { Component } from 'react'
import IdleTimer from 'react-idle-timer'

export default class YourApp extends Component {
  constructor(props) {
    super(props)
    this.idleTimer = null
    this.handleOnAction = this.handleOnAction.bind(this)
    this.handleOnActive = this.handleOnActive.bind(this)
    this.handleOnIdle = this.handleOnIdle.bind(this)
  }

  render() {
    return (
      <div>
        <IdleTimer
          ref={ref => { this.idleTimer = ref }}
          timeout={1000 * 60 * 15}
          onActive={this.handleOnActive}
          onIdle={this.handleOnIdle}
          onAction={this.handleOnAction}
          debounce={250}
        />
        {/* your app here */}
      </div>
    )
  }

  handleOnAction (event) {
    console.log('user did something', event)
  }

  handleOnActive (event) {
    console.log('user is active', event)
    console.log('time remaining', this.idleTimer.getRemainingTime())
  }

  handleOnIdle (event) {
    console.log('user is idle', event)
    console.log('last active', this.idleTimer.getLastActiveTime())
  }
}

Hook Usage

Run npm run example-hook to build and run the hook example. The example is a create-react-app project. IdleTimer is implemented in the App Component.

import React from 'react'
import { useIdleTimer } from 'react-idle-timer'
import App from './App'

export default function (props) {
  const handleOnIdle = event => {
    console.log('user is idle', event)
    console.log('last active', getLastActiveTime())
  }

  const handleOnActive = event => {
    console.log('user is active', event)
    console.log('time remaining', getRemainingTime())
  }

  const handleOnAction = (e) => {
    console.log('user did something', e)
  }

  const { getRemainingTime, getLastActiveTime } = useIdleTimer({
    timeout: 1000 * 60 * 15,
    onIdle: handleOnIdle,
    onActive: handleOnActive,
    onAction: handleOnAction,
    debounce: 500
  })

  return (
    <div>
      {/* your app here */}
    </div>
  )
}

Migration from v3 to v4

There are a few breaking changes in version 4:

  • Although still capable of rendering children, as of version 4 we don't pass children to IdleTimer. Unless you are really good with shouldComponentUpdate you should avoid using IdleTimer as a wrapper component.
  • The property startOnLoad has been renamed to startOnMount in order to make more sense in a React context.
  • The property activeAction has been renamed to onActive.
  • The property idleAction has been renamed to onIdle.

Documentation

Default Events

  • mousemove
  • keydown
  • wheel
  • DOMMouseScroll
  • mousewheel
  • mousedown
  • touchstart
  • touchmove
  • MSPointerDown
  • MSPointerMove
  • visibilitychange

Props

  • timeout {Number} - Idle timeout in milliseconds.
  • events {Array} - Events to bind. See default events for list of defaults.
  • onIdle {Function} - Function to call when user is now idle.
  • onActive {Function} - Function to call when user is no longer idle.
  • onAction {Function} - Function to call on user action.
  • debounce {Number} - Debounce the onAction function with delay in milliseconds. Defaults to 0. Cannot be set if throttle is set.
  • throttle {Number} - Throttle the onAction function with delay in milliseconds. Defaults to 0. Cannot be set if debounce is set.
  • eventsThrottle {Number} - Throttle the event handler. Helps to reduce cpu usage on repeated events (mousemove). Defaults to 200.
  • element {Object} - Defaults to document, may pass a ref to another element.
  • startOnMount {Boolean} - Start the timer when the component mounts. Defaults to true. Set to false to wait for user action before starting timer.
  • stopOnIdle {Boolean} - Stop the timer when user goes idle. Defaults to false. If set to true you will need to manually call reset() to restart the timer.
  • passive {Boolean} - Bind events in passive mode. Defaults to true.
  • capture {Boolean} - Bind events in capture mode. Defaults to true.

Methods

  • reset() {Void} - Resets the idleTimer.
  • pause() {Void} - Pauses the idleTimer.
  • resume() {Void} - Resumes a paused idleTimer.
  • getRemainingTime() {Number} - Returns the remaining time in milliseconds.
  • getElapsedTime() {Number} - Returns the elapsed time in milliseconds.
  • getLastIdleTime() {Number} - Returns the Timestamp the user was last idle.
  • getTotalIdleTime() {Number} - Returns the amount of time in milliseconds the user was idle.
  • getLastActiveTime() {Number} - Returns the Timestamp the user was last active.
  • getTotalActiveTime() {Number} - Returns the amount of time in milliseconds the user was active.
  • isIdle() {Boolean} - Returns whether or not user is idle.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].