Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
use-latest-callback
Advanced tools
React hook which returns the latest callback without changing the reference
React hook which returns the latest callback without changing the reference.
This is useful for scenarios such as event listeners where you may not want to resubscribe when the callback changes.
Open a Terminal in the project root and run:
npm install use-latest-callback
The useLatestCallback
hook accepts a function as its argument and returns a function that preserves its reference across renders.
const useLatestCallback = require('use-latest-callback');
// ...
function MyComponent() {
const callback = useLatestCallback((value) => {
console.log('Changed', value);
});
React.useEffect(() => {
someEvent.addListener(callback);
return () => someEvent.removeListener(callback);
}, [callback]);
return <>{/* whatever */}</>;
}
It's important to note that the callback is not intended to be called during the render phase. Only call the callback in response to an event.
FAQs
React hook which returns the latest callback without changing the reference
The npm package use-latest-callback receives a total of 439,208 weekly downloads. As such, use-latest-callback popularity was classified as popular.
We found that use-latest-callback demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.