Cette page est affichée en anglais. Une traduction française est en cours.
ConfigsJul 17, 2026·3 min de lecture

React Three Fiber — A React Renderer for Three.js

Build interactive 3D scenes declaratively with React components, leveraging the full power of Three.js through a familiar JSX-based API with automatic lifecycle management.

Prêt pour agents

Installation agent prête

Cet actif peut être installé après choix du runtime, vérification du plan et exécution de la commande adaptée.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
React Three Fiber
Commande d'installation directe
npx -y tokrepo@latest install 98f5fec7-8176-11f1-9bc6-00163e2b0d79 --target codex

À exécuter après confirmation du plan en dry-run.

Introduction

React Three Fiber (R3F) is a React renderer for Three.js that lets developers build 3D scenes using declarative JSX syntax. Instead of imperative Three.js boilerplate, you compose scenes with React components, gaining automatic resource disposal, event handling, and integration with the React ecosystem including state management and routing.

What React Three Fiber Does

  • Renders Three.js scenes as React component trees with JSX syntax
  • Manages the render loop, resizing, and disposal automatically
  • Provides pointer events (click, hover, drag) on 3D objects out of the box
  • Integrates with React state and lifecycle for reactive 3D updates
  • Works with the @react-three/drei companion library for common 3D helpers

Architecture Overview

R3F implements a custom React reconciler that maps JSX elements to Three.js objects. Each JSX tag (e.g., <mesh>, <boxGeometry>) creates and manages the corresponding Three.js instance. The reconciler handles mounting, updating props, and unmounting with proper GPU resource cleanup. A built-in render loop drives animation frames, and a raycaster provides DOM-like pointer events on 3D geometry.

Self-Hosting & Configuration

  • Install three, @react-three/fiber, and optionally @react-three/drei for helpers
  • Wrap your 3D scene in a <Canvas> component that handles the WebGL context
  • Configure camera, shadows, and pixel ratio via Canvas props
  • Use useFrame hook for per-frame animation logic
  • Add post-processing effects with @react-three/postprocessing

Key Features

  • Declarative 3D: compose scenes with JSX instead of imperative Three.js calls
  • Automatic cleanup: GPU resources are disposed when components unmount
  • Full Three.js access: any Three.js feature works within R3F components
  • Pointer events on 3D objects with the same API as DOM events
  • Ecosystem of companion libraries: drei (helpers), postprocessing, rapier (physics)

Comparison with Similar Tools

  • Plain Three.js — full control but requires manual lifecycle, event, and cleanup code; R3F automates all of this
  • Babylon.js — a complete engine with its own scene graph; R3F leverages React's component model instead
  • A-Frame — HTML-based 3D framework for WebXR; simpler entry point but less flexible than R3F for complex apps
  • Threlte — Svelte equivalent of R3F; choose based on your frontend framework preference

FAQ

Q: Does R3F add overhead compared to raw Three.js? A: The React reconciler adds minimal overhead. For most applications, the bottleneck is GPU rendering, not the component tree. Performance-critical sections can use refs to bypass React updates.

Q: Can I use existing Three.js code in R3F? A: Yes. You can wrap any Three.js object with the <primitive> component or use refs to access Three.js instances directly.

Q: Does it support VR and AR? A: Yes. R3F supports WebXR through the <XR> component from @react-three/xr, enabling VR and AR experiences.

Q: What is @react-three/drei? A: Drei is a companion library providing ready-made helpers like cameras, controls, loaders, shaders, and abstractions that reduce boilerplate in R3F projects.

Sources

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires