react-three-fiber
Skill0 starsChanged 7 months agoMITView on GitHub
React Three Fiber (R3F) — declarative Three.js for React. Use when the user is building 3D scenes with `@react-three/fiber`, working with `<Canvas>`, `useFrame`, `useThree`, `useLoader`, hits performance issues (jank, frozen shaders, GC stutter, re-renders in the render loop), or asks about R3F pitfalls, instancing, ref-based animation, or memoizing uniforms with Leva.
4 other projects use a version of this.
Adopted by
Most recently taken up by
- xenodeve/xeno-skillstheir own version, first seen Sep 26, 2026
- vercel-labs/json-rendertheir own version, first seen Sep 23, 2026
- SkotAlexsander/skillstheir own version, first seen Sep 16, 2026
- freshtechbro/claudedesignskillstheir own version, first seen Oct 25, 2025
Other versions4 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 4
- vercel-labs/json-render★ 18ksame name
- freshtechbro/claudedesignskills★ 975same name
- xenodeve/xeno-skills★ 2same name
- SkotAlexsander/skills★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository2 other files it gives its agents.
- procedural-noiseSkill
- tslSkill
The file
We split this skill into the rules it gives an agent
2 rules. 0 are common, 0 are distinctive, and 2 are very specific to this project.
0
Common
Most of the 4 edited versions we read keep these.
0
Distinctive
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 38
Mutate per-frame in
useFrame: Update .value in place — no new objects, no setState. - Very specific: line 39
Memoize the Leva control schema: if it's computed from props or state, so useControls doesn't tear down and rebuild the panel.
“Common” is measured: kept by at least 6 in 10 of the 4 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
React Three Fiber
Declarative Three.js as React components. The render loop runs outside React — useFrame fires every frame, but React reconciliation does not. Most R3F bugs and perf problems come from forgetting that boundary.
Performance pitfalls
The single most important rule: don't drive the render loop through React state. Everything below is a corollary.
- No
setStateinuseFrameor fast event handlers. Each setState triggers reconciliation; at 60fps you'll re-render the whole subtree 60 times per second. Mutate refs instead. Use thedeltaarg fromuseFramefor refresh-rate-independent motion. - Animate in
useFrame(lerp/damp) or withreact-spring. Both run outside React. Driving an animation through React state is the most common source of R3F jank. - Don't reactively subscribe components to fast-changing store state. Selector subscriptions re-render on every change. Inside
useFrame, read withstore.getState()directly — no subscription, no re-render. - Share materials and geometries. Each unique material/geometry is a shader compile and a GPU upload. Reuse them across meshes. For many similar meshes, use instancing (
<instancedMesh>or drei's<Instances>). - Avoid remounting expensive subtrees. Toggle
visibleinstead of conditionally rendering. Mounting recompiles materials and re-uploads geometry. - Hoist temp objects. Allocating a
new THREE.Vector3()insideuseFrameallocates 60 objects per second per call site. The GC pause shows up as periodic stutter. HoistVector3/Matrix4/Coloroutside the frame callback and reuse via.set(). - Use
useLoaderfor assets. Loaders cache globally by URL — callinguseLoader(GLTFLoader, url)from multiple components hits the cache. For GLTF scenes you reuse heavily, prefergltfjsx-generated components: the JSX is immutable and the underlying buffers are shared. - For expensive state changes, wrap in
startTransition. Concurrent mode de-prioritizes the work so the render loop stays responsive while the heavy update lands on a later commit. - Memoize uniforms objects. A new uniforms object every render means
useFramemutates a stale reference while the material reads from a fresh one — the shader appears frozen even thoughuniforms.uTime.valueis incrementing.useMemoit once with[]deps.
Leva + uniforms
The pattern for live-tweaking uniforms with Leva without re-rendering. All five rules below collapse to one principle: the uniforms object is mutated, never replaced.
- Memoize the uniforms object with
[]deps so the reference is stable for the lifetime of the component. - Drive Leva via
onChange, not the return value. Mutateuniforms.*.valuedirectly; never callsetState. - Mutate per-frame in
useFrame. Update.valuein place — no new objects, nosetState. - Memoize the Leva control schema if it's computed from props or state, so
useControlsdoesn't tear down and rebuild the panel. - Reuse
ColorandVectorinstances.color.set(hex)andvec.set(x, y, z)mutate in place; assigning a fresh instance allocates and orphans the old one.
import { useMemo } from 'react'
import { useFrame } from '@react-three/fiber'
import { useControls } from 'leva'
import * as THREE from 'three'
function Scene() {
const uniforms = useMemo(
() => ({
uTime: { value: 0 },
uColor: { value: new THREE.Color('#ff0') },
}),
[],
)
useControls({
color: {
value: '#ff0',
onChange: (v: string) => uniforms.uColor.value.set(v),
},
})
useFrame((_, delta) => {
uniforms.uTime.value += delta
})
// ...pass `uniforms` into a ShaderMaterial
}For heavy work triggered by a control change, debounce the onChange or push the work into useFrame via a ref — never block the Leva input thread.
Canonical sources
- R3F pitfalls — the upstream pitfalls page; mirrors most of the above and adds details.
- Discover Three.js — tips — Three.js-level guidance that applies underneath R3F.
WebFetch these when a question reaches beyond the curated wisdom above (e.g. specific drei component APIs, post-processing, or render targets).
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

