Created
May 19, 2020 12:44
-
-
Save afahy/59ecfd86b272ccf0179da8ca2a60a298 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 React from 'react'; | |
export default function useUpdateEffect(callback, properties, cleanup) { | |
let initialized = React.useRef(false); | |
React.useEffect(() => { | |
if (initialized.current) { | |
callback(properties); | |
} else { | |
initialized.current = true; | |
} | |
return () => { | |
if (typeof cleanup === 'function') { | |
cleanup(); | |
} | |
} | |
}, properties); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment