Skip to content

Instantly share code, notes, and snippets.

@DWboutin
Created March 22, 2023 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DWboutin/b92588676d8a5e5b297fc3d32343b066 to your computer and use it in GitHub Desktop.
Save DWboutin/b92588676d8a5e5b297fc3d32343b066 to your computer and use it in GitHub Desktop.
usePrevious react hook
import { useEffect, useRef } from 'react'
function usePrevious<T>(value: T): T {
const ref = useRef(value)
useEffect(() => {
ref.current = value
}, [value])
return ref.current
}
export default usePrevious
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment