Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
react-timing-hooks
Advanced tools
React hooks for creating timing-related effects (setTimeout, setInterval, requestAnimationFrame, requestIdleCallback)
This library contains (or will contain) a bunch of hooks that can be used to trigger effects containing timeouts, intervals etc. without having to worry about storing "timeoutIds" or proper clean up of leaking timers. Apart from that this lib is super light-weight, since it doesn't include any other dependencies.
useEffect
)You often have timeouts that run under a certain condition. In these cases a cleanup
often has to be done in a separate useEffect
call that really only cleans up on
unmount.
You might have code like this for example:
import { useEffect } from 'react'
// ...
const timeoutId = useRef(null)
useEffect(() => {
if (depA && depB) {
timeoutId.current = setTimeout(() => doSomething(), 1000)
}
}, [depA, depB])
useEffect(() => {
return function onUnmount() {
if (timeoutId.current !== null) {
clearTimeout(timeoutId.current)
}
}
}, [timeoutId])
With react-timing-hooks
you can just write:
import { useTimeoutEffect } from 'react-timing-hooks'
// ...
useTimeoutEffect((timeout) => {
if (depA && depB) {
timeout(() => doSomething(), 1000)
}
}, [depA, depB])
react-timing-hooks
will automatically take care of cleaning up the timeouts for you.
Note: At this moment, useIntervalEffect
, and hooks for requestAnimationFrame
and requestIdleCallback
are still in development.
useTimeoutEffect(effectCallback, deps)
effectCallback
will receive one argument timeout(f, timeout)
that has the
same signature as a native setTimeout
deps
is your regular useEffect
dependency array
Example:
useTimeoutEffect(timeout => {
if (foo) {
timeout(() => doSomething(), 1000)
}
}, [foo])
useIntervalEffect(effectCallback, deps)
Note: Still in development.
effectCallback
will receive one argument interval(f, timeout)
that has the
same signature as a native setInterval
deps
is your regular useEffect
dependency array
Example:
useIntervalEffect(interval => {
if (foo) {
interval(() => doSomething(), 1000)
}
}, [foo])
FAQs
React hooks for setTimeout, setInterval, requestAnimationFrame, requestIdleCallback
The npm package react-timing-hooks receives a total of 829 weekly downloads. As such, react-timing-hooks popularity was classified as not popular.
We found that react-timing-hooks demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.