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

@restart/hooks

Package Overview
Dependencies
Maintainers
2
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@restart/hooks - npm Package Compare versions

Comparing version 0.3.18 to 0.3.19

12

cjs/useInterval.d.ts

@@ -9,3 +9,3 @@ /**

/**
* Creates a pasuable `setInterval` that is properly cleaned up when a component unmounted
* Creates a pausable `setInterval` that is properly cleaned up when a component unmounted
*

@@ -17,2 +17,12 @@ * @param fn an function run on each interval

declare function useInterval(fn: () => void, ms: number, paused: boolean): void;
/**
* Creates a pausable `setInterval` that is properly cleaned up when a component unmounted
*
* @param fn an function run on each interval
* @param ms The milliseconds duration of the interval
* @param paused Whether or not the interval is currently running
* @param runImmediately Whether to run the function immediately on mount or unpause
* rather than waiting for the first interval to elapse
*/
declare function useInterval(fn: () => void, ms: number, paused: boolean, runImmediately: boolean): void;
export default useInterval;

15

cjs/useInterval.js

@@ -12,3 +12,3 @@ "use strict";

function useInterval(fn, ms, paused) {
function useInterval(fn, ms, paused, runImmediately) {
if (paused === void 0) {

@@ -18,2 +18,6 @@ paused = false;

if (runImmediately === void 0) {
runImmediately = false;
}
var handle;

@@ -37,7 +41,12 @@ var fnRef = (0, _useCommittedRef.default)(fn); // this ref is necessary b/c useEffect will sometimes miss a paused toggle

(0, _react.useEffect)(function () {
schedule();
if (runImmediately) {
tick();
} else {
schedule();
}
return function () {
return clearTimeout(handle);
};
}, [paused]);
}, [paused, runImmediately]);
}

@@ -44,0 +53,0 @@

@@ -9,3 +9,3 @@ /**

/**
* Creates a pasuable `setInterval` that is properly cleaned up when a component unmounted
* Creates a pausable `setInterval` that is properly cleaned up when a component unmounted
*

@@ -17,2 +17,12 @@ * @param fn an function run on each interval

declare function useInterval(fn: () => void, ms: number, paused: boolean): void;
/**
* Creates a pausable `setInterval` that is properly cleaned up when a component unmounted
*
* @param fn an function run on each interval
* @param ms The milliseconds duration of the interval
* @param paused Whether or not the interval is currently running
* @param runImmediately Whether to run the function immediately on mount or unpause
* rather than waiting for the first interval to elapse
*/
declare function useInterval(fn: () => void, ms: number, paused: boolean, runImmediately: boolean): void;
export default useInterval;

@@ -10,3 +10,3 @@ import { useEffect } from 'react';

function useInterval(fn, ms, paused) {
function useInterval(fn, ms, paused, runImmediately) {
if (paused === void 0) {

@@ -16,2 +16,6 @@ paused = false;

if (runImmediately === void 0) {
runImmediately = false;
}
var handle;

@@ -35,9 +39,14 @@ var fnRef = useCommittedRef(fn); // this ref is necessary b/c useEffect will sometimes miss a paused toggle

useEffect(function () {
schedule();
if (runImmediately) {
tick();
} else {
schedule();
}
return function () {
return clearTimeout(handle);
};
}, [paused]);
}, [paused, runImmediately]);
}
export default useInterval;
{
"name": "@restart/hooks",
"version": "0.3.18",
"version": "0.3.19",
"main": "cjs/index.js",

@@ -42,3 +42,3 @@ "types": "cjs/index.d.ts",

"readme": "ERROR: No README data found!",
"_id": "@restart/hooks@0.3.17"
"_id": "@restart/hooks@0.3.18"
}

@@ -16,3 +16,3 @@ # @restart/hooks [![npm][npm-badge]][npm]

useInterval(() => loop(), false, 300)
useInterval(() => loop(), 300, false)
```

@@ -19,0 +19,0 @@

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