This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useRef, useCallback, useEffect } from 'react'; | |
// A callback that always closes over the latest data but keeps the same | |
// identity and will not be called after component unmounts | |
const useStableCallback = callback => { | |
const callbackRef = useRef(); | |
const memoCallback = useCallback( | |
(...args) => callbackRef.current && callbackRef.current(...args), | |
[], |