Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-timer-and-stopwatch

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-timer-and-stopwatch - npm Package Compare versions

Comparing version 0.6.5 to 0.6.6

7

package.json
{
"name": "react-timer-and-stopwatch",
"version": "0.6.5",
"version": "0.6.6",
"description": "A countdown timer and stopwatch hook for React",
"license": "MIT",
"type": "module",
"author": "Jacob Noonan",
"author": {
"name": "Jacob",
"email": "jcnooncode@gmail.com"
},
"repository": {

@@ -9,0 +12,0 @@ "type": "git",

@@ -10,2 +10,3 @@ # React Timer and Stopwatch hook

- [Stopwatch](#stopwatch)
- [Timer Status Booleans](#timer-status-booleans)
- [Control Functions](#control-functions)

@@ -132,4 +133,8 @@ - [Customization](#customization)

## Timer Status Booleans
There are three booleans on the the timer object returned by useTimer which reflect whether the timer is finished (`timerIsFinished`), paused (`timerIsPaused`), or past its finish (`pastFinish`). The only time `pastFinish` can be true is with a Unix timer.
***
## Control Functions
There are functions returned by **useTimer** which can pause, resume, and reset the timer/stopwatch. These are **togglePause**, **pauseTimer**, **resumeTimer**, and **resetTimer**. There's also a boolean returned, `timerIsPaused`, which shows if the Timer is currently paused or not.
There are functions returned by **useTimer** which can pause, resume, and reset the timer/stopwatch. These are **togglePause**, **pauseTimer**, **resumeTimer**, and **resetTimer**.
#### Example

@@ -159,3 +164,46 @@ ```jsx

```
**resetTimer** can reset the timer/stopwatch with the original options if no parameter is included, or you can include an options object in the first optional parameter (`adjustedOptions`) to either adjust the old options or replace the old options entirely. If you want to replace them, set the second optional parameter (`replaceOptions`) to true and be sure to include a new `create` object on your new options object.
**resetTimer** can reset the timer/stopwatch with the original options if no parameter is included, or you can include an options object in the first optional parameter (`adjustedOptions`) to either adjust the old options or replace the old options entirely. If you want to replace them, set the second optional parameter (`replaceOptions`) to true and be sure to include a new `create` object on your new options object.
#### Example
```jsx
const SomeReactComponent = () => {
const timer = useTimer({
create: {
timerWithDuration: {
time: { // Set to a duration of 30 seconds
seconds: 30
}
}
}
});
const {resetTimer timerText} = timer;
const resetAndAdjustOptions = () => { // These new options will essentially be patched onto the old options
resetTimer({
autoplay: false,
includeMilliseconds: true,
intervalRate: 37
});
}
const resetAndReplaceOptions = () => { // This will replace the old options entirely, effectively creating a new timer/stopwatch on reset
resetTimer({
create: {
stopwatch: {} // The timer was a Duration countdown timer, but after reset it will be a Stopwatch
},
includeMilliseconds: true,
intervalRate: 37
},
true);
}
const resetTimerWithOldOptions = () => {
resetTimer();
}
return (
<>
<span>Time Left: {timerText}</span>
<button onClick={resetAndAdjustOptions}>Reset Timer and Adjust Options</button>
<button onClick={resetAndReplaceOptions}>Reset Timer and Replace Options</button>
<button onClick={resetTimerWithOldOptions}>Reset Timer with Old Options</button>
</>
);
}
```

@@ -162,0 +210,0 @@ There are also functions to add and subtract time from the current timer/stopwatch. These are **addTime** and **subtractTime**. Both take either a number of milliseconds or alternatively a [time object](#terminology).

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc