useCallback Might Be What You Meant By useRef & useEffect

Sometimes we respond to React element mounts. The first instinct is to useRef & useEffect. But It’s wrong. What you really need is often useCallback.

setRef returned from useCallback
react-hooks warns about using useRef with useEffect
A sandbox where useRef as deps of useEffect fails to trigger it on time

useCallback

A sandbox where useCallback is used as a ref and detects renders on time

useState

useStateRef

useRefWithCallback

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store