nx.js
Concepts

Event Loop

Callback-based animation frame request

To hook into each frame of the event loop in nx.js, use the requestAnimationFrame() function. This allows your app to update its state at a fixed frame rate (60 FPS).

Example

src/main.ts
const ctx = screen.getContext('2d');
ctx.fillStyle = 'white';
ctx.font = '40px sans-serif';
 
// The `update()` function is called for every frame of the event loop
function update() {
  requestAnimationFrame(update);
 
  ctx.clearRect(0, 0, screen.width, screen.height);
  ctx.fillText(new Date().toISOString(), 10, 50);
}
 
update();

On this page