Skip to content

Instantly share code, notes, and snippets.

@townofdon
Last active December 18, 2019 15:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save townofdon/4356ef9e3e459d6822f2c5b42b386210 to your computer and use it in GitHub Desktop.
Save townofdon/4356ef9e3e459d6822f2c5b42b386210 to your computer and use it in GitHub Desktop.
Simple delayed Promise
const delay = (callback, time = 5000) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve();
}, time);
})
.then(callback);
}
// USAGE
//
// SIMPLE JS FUNCTION
// delay(() => console.log('hello'));
//
// LAZY LOADING A REACT COMPONENT
// const SomeComponent = React.lazy(() => delay(() => import("../some-component")));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment