Created
October 29, 2018 00:02
-
-
Save dispix/9b01e58ec371a0e5550267ab29ae444d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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