
Security News
Security Community Slams MIT-linked Report Claiming AI Powers 80% of Ransomware
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.
@swyg/corre
Advanced tools
🏃♂️ Declaratively control how and when your code is executed. Hooks for setTimeout, setInterval, rAF and more!
🏃♂️ Declaratively control how and when your code is executed. Hooks for setTimeout, setInterval, rAF and more!
npm install @swyg/corre
yarn install @swyg/corre
useTimeout(...)Calls window.setTimeout(...) declaratively.
const timeoutRef = useTimeout(
    callback: EffectCallback,
    delay: number | null,
    deps: React.DependencyList = [],
): MutableRefObject<number | null>;
If delay === null, the timer won't be set; if it's already set, it will be cleared.
If deps are passed, anytime any of them change, the previous timer will be cleared and a new one will be set. This means that:
deps are passed (and this never changes), the callback will be called only once.deps change faster than delay, the callback will never be called.Note callback is stored in a ref, so you don't need to pass its dependencies as deps if you don't want the behavior just described.
useInterval(...)Calls window.setInterval(...) declaratively.
const intervalRef = useInterval(
    callback: EffectCallback,
    delay: number | null,
    deps: React.DependencyList = [],
): MutableRefObject<number | null>
If delay === null, the timer won't be set; if it's already set, it will be cleared.
If deps are passed, anytime any of them change, the previous timer will be cleared and a new one will be set. This means that:
deps change faster than delay, the callback will never be called.Note callback is stored in a ref, so you don't need to pass its dependencies as deps if you don't want the behavior just described.
useRequestAnimationFrame(...) aliased useRAF(...)Calls window.requestAnimationFrame(...) declaratively.
const rafRef = useRequestAnimationFrame(
    callback: EffectCallback,
    isRunning: boolean,
): MutableRefObject<number | null>;
If isRunning === null, requestAnimationFrame won't be called; if it's already been called, it will be cancelled.
useThrottledRequestAnimationFrame(...) aliased useThrottledRAF(...)Calls window.requestAnimationFrame(...) wrapped in window.setInterval(...) declaratively.
This means this callback will be called through window.requestAnimationFrame(...) once every delay ms.
const [intervalRef, rafRef] = useThrottledRequestAnimationFrame(
    callback: EffectCallback,
    delay: number | null,
    isRunning: boolean = true,
): [
    MutableRefObject<number | null>,
    MutableRefObject<number | null>,
];
If delay === null or isRunning === null, the timer won't be set and requestAnimationFrame won't be called; if it's already set / it has already been called, it will be cleared, they'll be cleared / cancelled.
If deps are passed, anytime any of them change, the previous timer will be cleared and a new one will be set. This means that:
deps change faster than delay, the callback will never be called.useThrottledCallback(...)Returns a throttled version of callback that, when called:
callback if it's been more than delay ms since the last call.setTimeout to call the original callback once delay ms have passed since the last call.const throttledFn = useThrottledCallback<A extends any[]>(
    callback: (...args: A) => void,
    delay: number,
    deps: DependencyList = [],
    options: { makeResponsive: boolean } = {}
): (...args: A) => void;
If deps are passed, anytime any of them change, the previous timer will be cleared. This means that:
callback won't happen (unless the throttled function is called again).deps change faster than delay, the callback will never be called.Note callback is stored in a ref, so you don't need to pass its dependencies as deps if you don't want the behavior just described.
FAQs
🏃♂️ Declaratively control how and when your code is executed. Hooks for setTimeout, setInterval, rAF and more!
We found that @swyg/corre demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 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.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.

Research
/Security News
Socket researchers found 10 typosquatted npm packages that auto-run on install, show fake CAPTCHAs, fingerprint by IP, and deploy a credential stealer.