Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
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 514,090 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.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.