Skip to content

Instantly share code, notes, and snippets.

@bmcmahen
Created January 24, 2020 00:02
Show Gist options
  • Save bmcmahen/c08b4e0fd79512ca538dca15ee858be3 to your computer and use it in GitHub Desktop.
Save bmcmahen/c08b4e0fd79512ca538dca15ee858be3 to your computer and use it in GitHub Desktop.
useDeferredMount
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