Skip to content

Instantly share code, notes, and snippets.

@hoyangtsai
Created January 2, 2024 08:15
Show Gist options
  • Save hoyangtsai/488c944ee4e84dcfaeff3ccf27f53869 to your computer and use it in GitHub Desktop.
Save hoyangtsai/488c944ee4e84dcfaeff3ccf27f53869 to your computer and use it in GitHub Desktop.
#react #useEffect after paint
function useAfterPaintEffect(effect, dependencies) {
useEffect(() => {
requestAnimationFrame(() => {
setTimeout(() => {
effect();
}, 0);
});
}, dependencies);
}
@hoyangtsai
Copy link
Author

Source is from facebook/react#20863

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