Skip to content

Instantly share code, notes, and snippets.

@honzabrecka
Created October 1, 2019 15:04
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 honzabrecka/822ce7f4c62a2ff7287443c0de3e7ba4 to your computer and use it in GitHub Desktop.
Save honzabrecka/822ce7f4c62a2ff7287443c0de3e7ba4 to your computer and use it in GitHub Desktop.
import { useEffect } from 'react'
export default function useReference(lazyRefCreator, deps) {
const ref = useRef()
useEffect(() => {
ref.current = lazyRefCreator()
}, deps)
return ref.current
}
const x = useMemo(() => ..., [])
const x = useReference(() => ..., [])
@honzabrecka
Copy link
Author

  • useMemoLast
  • useMemoPrev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment