Skip to content

Instantly share code, notes, and snippets.

@devbyray
Created December 13, 2023 07:57
Show Gist options
  • Save devbyray/23a44bbd7f9682a4deb1bfc068324e5d to your computer and use it in GitHub Desktop.
Save devbyray/23a44bbd7f9682a4deb1bfc068324e5d to your computer and use it in GitHub Desktop.
Document Ready with a Promise in TypeScript
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