Last active
May 9, 2024 08:58
-
-
Save aneurysmjs/02a17a4d553a3e7681ffc546f98ad0b2 to your computer and use it in GitHub Desktop.
Artificially slow down a component
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
function Foo() { | |
const now = performance.now(); | |
/** | |
* The result of the first performance.now() call (stored in now) is subtracted from the current time. | |
* This effectively calculates the time elapsed since the loop began. | |
* | |
* the loop keeps running as long as it hasn't been a full second since the startTime was captured. | |
* Once the elapsed time hits or goes above 200ms, the loop condition becomes false, and the loop terminates. | |
*/ | |
while (performance.now() < now - 200) { // wait for 200ms | |
... | |
} | |
return <div>some foo</div>; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment