Ui useframe

From verekia/r3f-gamedev · View interactive version

Ui useframe is an AI agent skill from the GitHub repository verekia/r3f-gamedev. Sync UI elements outside the Canvas with the render loop using R3F v10's external useFrame.

How to use this skill

Skill file

UI useFrame

Sync UI elements outside the Canvas with the render loop using R3F v10's external useFrame.

Technique

Since React Three Fiber v10, useFrame can be used outside of the Canvas component. This allows updating DOM elements in sync with the 3D scene without using Drei's Html component.

Key Concepts

Usage

const Ui = () => {
  const ref = useRef<HTMLDivElement>(null)

  useFrame(() => {
    ref.current.innerText = `${position.x.toFixed(2)}, ${position.y.toFixed(2)}`
  }, { fps: 10 })

  return <div ref={ref} className="fixed top-4 right-4" />
}

// Place outside Canvas
<Canvas>
  <Scene />
</Canvas>
<Ui />

This skill is part of verekia's **r3f-gamedev**.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.