Skip to content

Imperative Updates

R3F does not ban imperative code. It gives you a cleaner place to put it.

  • Animating values in useFrame.
  • Updating camera targets or controls.
  • Tweaking material or geometry properties that come from external systems.
  • useRef to hold the object instance.
  • useFrame for per-frame logic.
  • useThree when you need access to shared renderer state like the camera, scene, or viewport.
const camera = useThree((state) => state.camera);
useEffect(() => {
camera.position.set(0, 2, 6);
}, [camera]);

Keep the scene shape declarative, then use imperative code in small, explicit islands for behavior that is naturally mutation-based.