Skip to content

Instantly share code, notes, and snippets.

@stephenway
Created December 16, 2019 20:59
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 stephenway/b89b66cddf554648d4cf114f6e19bad2 to your computer and use it in GitHub Desktop.
Save stephenway/b89b66cddf554648d4cf114f6e19bad2 to your computer and use it in GitHub Desktop.
React Hook to Expose previous props for use in useEffect hook
import { useRef } from 'react'
const usePrevious = value => {
const ref = useRef()
useEffect(() => {
ref.current = 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