Last active
December 18, 2019 15:01
-
-
Save townofdon/4356ef9e3e459d6822f2c5b42b386210 to your computer and use it in GitHub Desktop.
Simple delayed Promise
This file contains 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
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