Skip to content

Instantly share code, notes, and snippets.

@aneurysmjs
Last active May 9, 2024 08:58
Show Gist options
  • Save aneurysmjs/02a17a4d553a3e7681ffc546f98ad0b2 to your computer and use it in GitHub Desktop.
Save aneurysmjs/02a17a4d553a3e7681ffc546f98ad0b2 to your computer and use it in GitHub Desktop.
Artificially slow down a component
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