Imperative Updates
R3F does not ban imperative code. It gives you a cleaner place to put it.
Good Uses For Imperative Updates
Section titled “Good Uses For Imperative Updates”- Animating values in
useFrame. - Updating camera targets or controls.
- Tweaking material or geometry properties that come from external systems.
Common Tools
Section titled “Common Tools”useRefto hold the object instance.useFramefor per-frame logic.useThreewhen 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]);The Goal
Section titled “The Goal”Keep the scene shape declarative, then use imperative code in small, explicit islands for behavior that is naturally mutation-based.