import React from 'react' ; export function useLatestCallback < Args extends any [ ] , Output > ( callback ) { const callbackRef = React . useRef < ( ... args : Args ) => Output > ( callback ) ; callbackRef . current = callback ; return React . useMemo ( ( ) => { return ( ... args ) => { return callbackRef . current ( ... args ) ; } ; } , [ ] ) ; }