Skip to content

Instantly share code, notes, and snippets.

@dispix
Created October 29, 2018 00:02
Show Gist options
  • Save dispix/9b01e58ec371a0e5550267ab29ae444d to your computer and use it in GitHub Desktop.
Save dispix/9b01e58ec371a0e5550267ab29ae444d to your computer and use it in GitHub Desktop.
import { useRef, useEffect } from 'react'
function useUpdate(fn) {
const mounting = useRef(true)
useEffect(() => {
if (mounting.current) {
mounting.current = false
} else {
fn()
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment