Created
December 13, 2023 07:57
-
-
Save devbyray/23a44bbd7f9682a4deb1bfc068324e5d to your computer and use it in GitHub Desktop.
Document Ready with a Promise in TypeScript
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
export function docReady(): Promise<void> { | |
return new Promise((resolve) => { | |
if (document.readyState === 'interactive') { | |
resolve() | |
} else { | |
window.addEventListener('DOMContentLoaded', () => { | |
resolve() | |
}) | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment