All Projects → vydimitrov → use-elapsed-time

vydimitrov / use-elapsed-time

Licence: MIT license
React hook to measure elapsed time using requestAnimationFrame

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to use-elapsed-time

stook
A minimalist design state management library for React.
Stars: ✭ 86 (+104.76%)
Mutual labels:  hooks
roover
🐱 A lightweight audio library for React apps.
Stars: ✭ 70 (+66.67%)
Mutual labels:  hooks
use-detect-print
A react hook to detect when a page is being printed
Stars: ✭ 55 (+30.95%)
Mutual labels:  hooks
jedisdb
redis like key-value state management solution for React
Stars: ✭ 13 (-69.05%)
Mutual labels:  hooks
angulareact
A way to seamlessly integrate React and AngularJS
Stars: ✭ 17 (-59.52%)
Mutual labels:  hooks
snake-design
🐍 a react component library based React hooks
Stars: ✭ 33 (-21.43%)
Mutual labels:  hooks
react-zeno
The React companion to Zeno, a Redux implementation optimized for Typescript.
Stars: ✭ 14 (-66.67%)
Mutual labels:  hooks
husky-elixir
🐶 Git hooks made easy
Stars: ✭ 47 (+11.9%)
Mutual labels:  hooks
no-redux
⚛️ 🎣 Experimenting with using hooks and context instead of Redux
Stars: ✭ 79 (+88.1%)
Mutual labels:  hooks
react-use-observer
Performant react hooks for WebApi Observers, useResizeObserver, useInteractionObserver, useMutationObserver
Stars: ✭ 19 (-54.76%)
Mutual labels:  hooks
uot
🦁 A tiny setTimeout alternative with progress.
Stars: ✭ 43 (+2.38%)
Mutual labels:  requestanimationframe
coconat
🍥 StarterKit Builder for rocket-speed App creation on 🚀 React 17 + 📙 Redux 4 + 🚠 Router 5 + 📪 Webpack 5 + 🎳 Babel 7 + 📜 TypeScript 4 + 🚔 Linters 23 + 🔥 HMR 3
Stars: ✭ 95 (+126.19%)
Mutual labels:  hooks
react-use-redux
Alternative Redux bindings with upcoming React hooks
Stars: ✭ 31 (-26.19%)
Mutual labels:  hooks
use-redux-hook
A simple react hook to get access to redux store
Stars: ✭ 13 (-69.05%)
Mutual labels:  hooks
react-supabase
React Hooks library for Supabase
Stars: ✭ 168 (+300%)
Mutual labels:  hooks
use-scroll-direction
A simple, performant, and cross-browser hook for detecting scroll direction in your next react app.
Stars: ✭ 24 (-42.86%)
Mutual labels:  hooks
statery
Surprise-Free State Management! Designed for React with functional components, but can also be used with other frameworks (or no framework at all.)
Stars: ✭ 28 (-33.33%)
Mutual labels:  hooks
transition-hook
☄️ An extremely light-weight react transition animation hook which is simpler and easier to use than react-transition-group
Stars: ✭ 250 (+495.24%)
Mutual labels:  hooks
slotjs
🎰 Circular slot machine mobile-first SPA built using JavaScript, CSS variables and Emojis!
Stars: ✭ 90 (+114.29%)
Mutual labels:  requestanimationframe
scala-basic-skeleton
Starting point if you want to bootstrap a project in Scala
Stars: ✭ 16 (-61.9%)
Mutual labels:  hooks

useElapsedTime React hook

npm npm Codecov npm bundle size

React hook to measure elapsed time using requestAnimationFrame. The time measurement can be played and paused, additionally the start time and duration can be set. The primary use case of the hooks is in animations where the most important part of the animation is time.

  • Toggle play/pause
  • Set start time and duration
  • Adjust update interval to your need

Installation

yarn add use-elapsed-time

Basic usage

import { useElapsedTime } from 'use-elapsed-time'

const MyComponent = () => {
  const { elapsedTime } = useElapsedTime({ isPlaying: true })

  return elapsedTime
}

Edit epic-dream-hn62k

Function signature

  const {
    elapsedTime: number,
    reset: (newStartAt: number) => void
  } = useElapsedTime({
    isPlaying: boolean,
    duration?: number,
    startAt?: number,
    updateInterval?: number,
    onComplete?: (totalElapsedTime: number) => void | { shouldRepeat?: boolean, delay?: number, newStartAt?: number },
    onUpdate?: (elapsedTime: number) => void
  })

Props

Prop Name Type Default Description
isPlaying boolean - Indicates if the loop to get the elapsed time is running or it is paused
duration number - Animation duration in seconds
startAt number 0 Shift the start time to a different value than 0
updateInterval number 0 Update interval in seconds. Determines how often the elapsed time value will change. When set to 0 the value will update on each key frame
onComplete (totalElapsedTime: number) => void | { shouldRepeat: boolean, delay: number } - onComplete callback will be fired when the duration is reached. The callback will receive as an argument the totalElapsedTime in seconds. onComplete can be used to restart the elapsed time loop by returning an object with the following params: shouldRepeat - indicates if the loop should start over; delay - delay before looping again in seconds; newStartAt - change the startAt value before looping again
onUpdate (elapsedTime: number) => void - On time update event handler. It receives the current elapsedTime time in seconds

Return value

The hook returns an object with elapsedTime in seconds and reset method - { elapsedTime, reset }

Browser support

The hook supports all modern browsers targeting es6. Internet Explorer (IE) is not longer supported.

Use cases

Countdown timer
Edit priceless-hill-2tbiq

Count up animation
Edit hungry-cray-hl6wn

Non-liner path animation
Edit inspiring-austin-d6ol6

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