Skip to content

Commit

Permalink
feat(util): add next frame helper
Browse files Browse the repository at this point in the history
  • Loading branch information
fallenoak committed Dec 25, 2023
1 parent eaf40f2 commit 5101f62
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { nextFrame } from './util';

export { nextFrame };
11 changes: 11 additions & 0 deletions src/lib/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Returns a promise that settles after the next frame renders. Useful for spacing synchronous
* work on the main thread.
*/
const nextFrame = () => {
return new Promise<void>((resolve) => {
requestAnimationFrame(() => resolve());
});
};

export { nextFrame };

0 comments on commit 5101f62

Please sign in to comment.