Created
January 2, 2024 08:15
-
-
Save hoyangtsai/488c944ee4e84dcfaeff3ccf27f53869 to your computer and use it in GitHub Desktop.
#react #useEffect after paint
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
function useAfterPaintEffect(effect, dependencies) { | |
useEffect(() => { | |
requestAnimationFrame(() => { | |
setTimeout(() => { | |
effect(); | |
}, 0); | |
}); | |
}, dependencies); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Source is from facebook/react#20863