Skip to content

Instantly share code, notes, and snippets.

@nickytonline
Last active May 2, 2024 17:30
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save nickytonline/069fc006d1946279a31fed10a61d08c5 to your computer and use it in GitHub Desktop.
Save nickytonline/069fc006d1946279a31fed10a61d08c5 to your computer and use it in GitHub Desktop.
async/await"able DOM event handlers
// async/await"able" DOM event handlers
async function getMeSomeData() {
// ...
return data
}
document.addEventListener('DOMContentLoaded', async () => {
const someContainer = document.getElementById('someContainer');
let markup = null;
try {
markup = await getMeSomeData();
} catch(e) {
markup = 'Something bad happened :(';
}
someContainer.innerHTML = markup;
});
@PAX523
Copy link

PAX523 commented Jun 4, 2021

Thanks! :-)

@nickytonline
Copy link
Author

😎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment