Last active
February 1, 2020 16:24
-
-
Save bmcmahen/b582e0c17005472d128b8b4d12ec75d7 to your computer and use it in GitHub Desktop.
Deferred mounting hook
This file contains hidden or 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 { 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