
Product
Redesigned Repositories Page: A Faster Way to Prioritize Security Risk
Our redesigned Repositories page adds alert severity, filtering, and tabs for faster triage and clearer insights across all your projects.
react-use-event-hook
Advanced tools
Same as React's `useCallback`, but returns a stable reference.
Same as React's useCallback
, but returns a stable reference.
This library is a user-land implementation of the useEvent
hook, proposed in this RFC.
npm install react-use-event-hook
(this example was copied from the RFC)
You can wrap any event handler into useEvent
.
import useEvent from 'react-use-event-hook';
function Chat() {
const [text, setText] = useState('');
const onClick = useEvent(() => {
sendMessage(text);
});
return <SendButton onClick={onClick} />;
}
The code inside useEvent
“sees” the props/state values at the time of the call.
The returned function has a stable identity even if the props/state it references change.
There is no dependency array.
FAQs
Same as React's `useCallback`, but returns a stable reference.
The npm package react-use-event-hook receives a total of 24,194 weekly downloads. As such, react-use-event-hook popularity was classified as popular.
We found that react-use-event-hook 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.
Product
Our redesigned Repositories page adds alert severity, filtering, and tabs for faster triage and clearer insights across all your projects.
Security News
Slopsquatting is a new supply chain threat where AI-assisted code generators recommend hallucinated packages that attackers register and weaponize.
Security News
Multiple deserialization flaws in PyTorch Lightning could allow remote code execution when loading untrusted model files, affecting versions up to 2.4.0.