react-three-fiber
Use this skill when work touches 3D rendering, WebGL scenes, interactive 3D elements, three.js, immersive UI surfaces, particle systems, animated geometry, shader work, or anything that turns a flat screen into a spatial/dimensional experience. Especially relevant for hero animations, product visualization, scroll-driven 3D, branded interactive landing pages, or experiences that need to feel premi
Front matter
name: react-three-fiber
description: Use this skill when work touches 3D rendering, WebGL scenes, interactive 3D elements, three.js, immersive UI surfaces, particle systems, animated geometry, shader work, or anything that turns a flat screen into a spatial/dimensional experience. Especially relevant for hero animations, product visualization, scroll-driven 3D, branded interactive landing pages, or experiences that need to feel premium-tactile beyond standard 2D motion. Apply whenever a flat layout would benefit from depth, parallax, lighting, or 3D-rendered geometry — including 360° product views, animated logos, particle backgrounds, and any moment where the visual brief reads "make it feel premium / cinematic / tactile."
license: MITreact-three-fiber — bring three.js into React, declaratively
@react-three/fiber (R3F) is a React renderer for three.js. It lets you build 3D scenes with the same component mental model you already use for 2D React UI. When this skill activates, follow the playbook below before writing any 3D code.
When to reach for R3F
- A hero section would feel premium with an animated 3D object (logo, product, abstract geometry).
- A landing page's CTA is "make it feel cinematic" / "make it feel tactile."
- Product visualization — 360° views, exploded diagrams, configurators.
- Particle systems or shader-driven backgrounds.
- Scroll-driven 3D narratives (Bruno Simon
lusion.co-style sites).
When NOT to reach for R3F
- The page is content-heavy and 3D would be decorative-only (perf cost > UX gain).
- Target audience is on low-end mobile or older browsers without WebGL2 (always provide a 2D fallback).
- A 2D CSS/Framer Motion solution would accomplish the same emotional result with 10× less perf cost.
Install
npm install three @types/three @react-three/fiber
# Recommended companions:
npm install @react-three/drei # helpers (cameras, controls, loaders, abstractions)
npm install @react-three/postprocessing # bloom, depth-of-field, color-grading
# Optional, situational:
npm install @react-three/gltfjsx # GLTF model → JSX components
npm install @react-three/rapier # 3D physics
npm install @react-three/xr # VR/ARCritical version pairing
- R3F v8 requires React 18. R3F v9 requires React 19. Mismatch = silent runtime failures or hydration mismatches.
- three.js peer dep is locked to a minor — check
@react-three/fiberpackage.json before bumping three independently.
Canonical patterns
Basic scene scaffold
import { Canvas } from '@react-three/fiber';
import { OrbitControls } from '@react-three/drei';
export function Hero() {
return (
<Canvas camera={{ position: [0, 0, 5], fov: 45 }} dpr={[1, 2]}>
<ambientLight intensity={0.5} />
<directionalLight position={[5, 5, 5]} intensity={1} />
<mesh>
<boxGeometry args={[1, 1, 1]} />
<meshStandardMaterial color="hotpink" />
</mesh>
<OrbitControls />
</Canvas>
);
}Frame loop with useFrame
import { useFrame } from '@react-three/fiber';
import { useRef } from 'react';
import type { Mesh } from 'three';
function SpinningBox() {
const ref = useRef<Mesh>(null!);
useFrame((_, delta) => { ref.current.rotation.x += delta; });
return <mesh ref={ref}><boxGeometry /><meshStandardMaterial color="orange" /></mesh>;
}GLTF model loading with Suspense
import { Suspense } from 'react';
import { useGLTF } from '@react-three/drei';
function Model() {
const gltf = useGLTF('/path/to/model.glb');
return <primitive object={gltf.scene} />;
}
// Always wrap in Suspense — model loading is async
<Canvas>
<Suspense fallback={null}>
<Model />
</Suspense>
</Canvas>Gotchas that bite beginners
- No performance penalty vs vanilla three.js. R3F is just a renderer — three.js scene graph underneath is identical. React's scheduling makes large scenes actually faster than imperative three.js code.
- Components render OUTSIDE React's reconciliation cycle. State changes inside
useFramedo NOT trigger React re-renders. Use refs + mutate directly for per-frame updates. useFrameis required for animation. Don't try to usesetIntervalorrequestAnimationFramedirectly — R3F has its own frame loop tied to the Canvas lifecycle.- DPR (device pixel ratio) clamping matters.
dpr={[1, 2]}caps at 2× — without this, retina displays render 4× pixels = perf killer. - WebGL2 fallback. Some users (old iOS, locked-down corporate browsers) don't have WebGL2. Provide a
<canvas>2D fallback or detect vianavigator.gpu/WEBGL2_RENDERING_CONTEXTbefore mounting the R3F Canvas. glprop for tuning.<Canvas gl={{ antialias: true, alpha: true, powerPreference: 'high-performance' }}>— defaults work for hero scenes; tune only when needed.- Postprocessing is heavy. Bloom/DOF/SSAO can drop framerate hard on mid-range devices. Profile before shipping.
Performance baseline (target on mid-range laptop)
- 60fps with 1-3 objects, basic lighting, no postprocessing.
- 60fps with up to ~20 objects + 1 postprocessing pass.
- 30fps with heavy shader work or 100+ objects — only acceptable for animated backgrounds, not interactive scenes.
Canonical docs + learning resources
- R3F docs (canonical): https://docs.pmnd.rs/react-three-fiber/
- drei docs: https://github.com/pmndrs/drei
- three.js docs: https://threejs.org/docs/
- three.js examples (treasure trove): https://threejs.org/examples/
- Bruno Simon's Three.js Journey: https://threejs-journey.com (R3F chapter is the gold-standard tutorial)
- Discover Three.js (free book): https://discoverthreejs.com/
Compose with
- For motion patterns + easing, also load
design-motion-principles. - For overall design quality + slop avoidance, also load
frontend-design+taste-skill. - For premium polish on micro-interactions surrounding the 3D scene, also load
emil-kowalski-design.
Source: written by One Giant Leap.
Related entries
There are more like this in the members library
The Claude Code library holds 13,843 entries. Members can search all of them by meaning and read every one in full.