Skip to content

Instantly share code, notes, and snippets.

@bmcmahen
Last active February 1, 2020 16:24
Show Gist options
  • Save bmcmahen/b582e0c17005472d128b8b4d12ec75d7 to your computer and use it in GitHub Desktop.
Save bmcmahen/b582e0c17005472d128b8b4d12ec75d7 to your computer and use it in GitHub Desktop.
Deferred mounting hook
import { useState, useEffect } from 'react';
function useDeferredMount() {
const [shouldMount, setShouldMount] = useState(false);
useEffect(() => {
window.requestAnimationFrame(() => {
window.requestAnimationFrame(() => {
setShouldMount(true);
});
});
});
return shouldMount;
}
export default useDeferredMount;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment