Skip to content

Instantly share code, notes, and snippets.

Avatar

Pavlo B. zetorama

View GitHub Profile
@zetorama
zetorama / useCurrent.js
Last active Oct 30, 2019
useCurrent*/useBound* — hooks to bind callbacks to "whatever current value is"
View useCurrent.js
import { useRef, useCallback, useEffect } from 'react'
function useCurrentGetter(value) {
const refValue = useRef(value);
useEffect(() => {
refValue.current = value;
}, [value]);
return useCallback(() => refValue.current, [refValue]);
}