
Security News
CISA Kills Off RSS Feeds for KEVs and Cyber Alerts
CISA is discontinuing official RSS support for KEV and cybersecurity alerts, shifting updates to email and social media, disrupting automation workflows.
use-delayed-state
Advanced tools
React hook for setting State with delay
This is an enhanced useState
hook which accepts delay for setState
as an extra argument. In most basic form it works same as React useState
hook.
It can be used for debouncing which simply delays all consecuative attempts for setting a state and if the last call persist for enough time the actual setState
runs.
It is also a handy tool for applying timing logics inside react components e.g. Showing a notification for few seconds.
npm install --save use-delayed-state
import React from 'react'
import useDelayedState from 'use-delayed-state'
export default function myComponent() {
const [state, setState] = useDelayedState(
'Hello, I will be change in 5 seconds'
)
setState('I am new State', 5000)
return <div>{state}</div>
}
In above example State
will be updated after 5 second.
Debouncing example is more advance implementation of this hook which the source code is available here.
const [state, setState, cancelSetState] = useDelayedState(initialState);
// works like regular useState hook
// it will not cancel any ongoing delayed setStates
setState(newState); // or setState(newState, 0)
// setState with delay
// duration unit is millisecond
// it will cancel any ongoing delayed setStates
setState(newState, duration);
// canceling any ongoing delayed state
cancelSetState();
// setState along with setState with delay in one render
// below codes set State to newState and it will set State to futureState after 2s
setState(newState);
setState(futureState, 2000);
MIT © makannew
FAQs
React hook for setting State with delay
The npm package use-delayed-state receives a total of 11,264 weekly downloads. As such, use-delayed-state popularity was classified as popular.
We found that use-delayed-state demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
CISA is discontinuing official RSS support for KEV and cybersecurity alerts, shifting updates to email and social media, disrupting automation workflows.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.