Use Latest Callback
use-latest-callback
React hook which returns the latest callback without changing the reference
Utilities
react
use-event
use-callback
use-latest-callback
Utilities
javascript
npm
frontend
open source
ui
Stars
45
Weekly
7.7M
Open issues
6
Bundle
~15 kB
Installation
npm install use-latest-callbackCode example
import { useLatestCallback } from "use-latest-callback";
export function Example() {
const value = useLatestCallback();
return <p>{String(value)}</p>;
}Pros & cons
Pros
- Actively maintained by Satyajit Sahoo
- 7.7M weekly downloads. Battle tested
- First-class TypeScript definitions
- MIT licensed
Considerations
- Adds roughly ~15 kB to your bundle
- Needs client-only rendering in SSR frameworks
- Not supported in React Native
- 6 open issues on GitHub