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

react-timing-hooks

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-timing-hooks - npm Package Compare versions

Comparing version 1.4.0 to 1.4.1

7

CHANGELOG.md

@@ -5,2 +5,9 @@ # Changelog

### [1.4.1](https://github.com/EricLambrecht/react-timing-hooks/compare/v1.4.0...v1.4.1) (2020-07-25)
### Bug Fixes
* Fix timeouts not being properly unmounted (if more than 1) ([df2d247](https://github.com/EricLambrecht/react-timing-hooks/commit/df2d2476a5bd899ba8a362cb2ae5636f6d4089ab)), closes [#4](https://github.com/EricLambrecht/react-timing-hooks/issues/4)
## [1.4.0](https://github.com/EricLambrecht/react-timing-hooks/compare/v1.3.2...v1.4.0) (2020-06-12)

@@ -7,0 +14,0 @@

21

dist/index.es.js
import { useRef, useCallback, useEffect, useState } from 'react';
const useTimeoutEffect = (effect, deps) => {
const timeoutId = useRef(null);
const timeoutIds = useRef([]);
const timeoutFunc = useCallback((handler, timeout) => {
timeoutId.current = setTimeout(handler, timeout);
}, [timeoutId]);
const id = setTimeout(handler, timeout);
timeoutIds.current.push(id);
}, [timeoutIds]);
useEffect(() => {
return effect(timeoutFunc, () => {
if (timeoutId.current) {
clearTimeout(timeoutId.current);
if (timeoutIds.current.length > 0) {
timeoutIds.current.forEach(id => {
clearTimeout(id);
});
}

@@ -17,7 +20,9 @@ });

return function onUnmount() {
if (timeoutId.current !== null) {
clearTimeout(timeoutId.current);
if (timeoutIds.current.length > 0) {
timeoutIds.current.forEach(id => {
clearTimeout(id);
});
}
};
}, [timeoutId]);
}, [timeoutIds]);
};

@@ -24,0 +29,0 @@

@@ -8,10 +8,13 @@ 'use strict';

const useTimeoutEffect = (effect, deps) => {
const timeoutId = react.useRef(null);
const timeoutIds = react.useRef([]);
const timeoutFunc = react.useCallback((handler, timeout) => {
timeoutId.current = setTimeout(handler, timeout);
}, [timeoutId]);
const id = setTimeout(handler, timeout);
timeoutIds.current.push(id);
}, [timeoutIds]);
react.useEffect(() => {
return effect(timeoutFunc, () => {
if (timeoutId.current) {
clearTimeout(timeoutId.current);
if (timeoutIds.current.length > 0) {
timeoutIds.current.forEach(id => {
clearTimeout(id);
});
}

@@ -22,7 +25,9 @@ });

return function onUnmount() {
if (timeoutId.current !== null) {
clearTimeout(timeoutId.current);
if (timeoutIds.current.length > 0) {
timeoutIds.current.forEach(id => {
clearTimeout(id);
});
}
};
}, [timeoutId]);
}, [timeoutIds]);
};

@@ -29,0 +34,0 @@

{
"name": "react-timing-hooks",
"version": "1.4.0",
"version": "1.4.1",
"description": "React hooks for setTimeout, setInterval, requestAnimationFrame, requestIdleCallback",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -54,2 +54,6 @@ [![npm](https://flat.badgen.net/npm/v/react-timing-hooks)](https://www.npmjs.com/package/react-timing-hooks)

```
## Documentation
[https://ericlambrecht.github.io/react-timing-hooks/](https://ericlambrecht.github.io/react-timing-hooks/)

@@ -115,6 +119,2 @@ ## Why bother?

In this case `react-timing-hooks` automatically took care of cleaning up the timeout for you (if the component is mounted for less than a second for instance).
## Documentation
[https://ericlambrecht.github.io/react-timing-hooks/](https://ericlambrecht.github.io/react-timing-hooks/)

@@ -121,0 +121,0 @@

Sorry, the diff of this file is not supported yet

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