menu

JavaScript

A community to get help with JavaScript, find jobs, outsource and much more!

Channels
# All channels
view-forward
# General
view-forward
# Jobs
view-forward
# Node.js
view-forward
# React
view-forward
# Snippets
view-forward
# Vanilla
view-forward
# Vue.js
view-forward
Team

Async RAF

February 16, 2020 at 11:10am (Edited 4 months ago)
When you want to get a value from requestAnimationFrame, instead of:
const area = await new Promise((resolve) => {
window.requestAnimationFrame(() => {
const { offsetWidth, offsetHeight } = someElement;
resolve(offsetWidth * offsetHeight);
});
});
You can use AsynRAF:
const area = await asyncRaf(() => {
const { offsetWidth, offsetHeight } = someElement;
return offsetWidth * offsetHeight;
});
https://github.com/uditalias/async-raf
No messages yet