Skip to content

Additional Exports

Fresh

Additional utility exports available from @react-three/fiber.

ExportUsage
addEffectAdds a global render callback which is called each frame
addAfterEffectAdds a global after-render callback which is called each frame
addTailAdds a global callback which is called when rendering stops
buildGraphCollects nodes and materials from a THREE.Object3D
flushGlobalEffectsFlushes global render-effects for when manually driving a loop
flushSyncForce React to flush any updates synchronously and immediately
invalidateForces view global invalidation
advanceAdvances the frameloop (given that it's set to 'never')
extendExtends the native-object catalogue
createPortalCreates a portal (React feature for re-parenting)
createRootCreates a root that can render three JSX into a canvas
eventsDOM pointer-event system
applyPropsapplyProps(element, props) sets element properties
actUsage with react-testing
useInstanceHandleExposes react-internal local state from instance.__r3f

extend

Extends the native-object catalogue so third-party or custom elements can be used declaratively:

jsx
import { extend } from '@react-three/fiber'
import { OrbitControls } from 'three-stdlib'

extend({ OrbitControls })

// Now usable as JSX
<orbitControls />

invalidate

Forces a re-render. Useful when frameloop="demand" and something changes outside of React's awareness:

jsx
import { invalidate } from '@react-three/fiber'

// Request a new frame to be rendered
invalidate()

INFO

Calling invalidate() will not render immediately — it merely requests a new frame. Calling it multiple times will not render multiple times.

advance

Advance one tick of the render loop. Only works when frameloop === 'never':

jsx
import { advance } from '@react-three/fiber'

advance(timestamp)

createPortal

Creates a portal for re-parenting React content into a different three.js scene or object:

jsx
import { createPortal } from '@react-three/fiber'

function MyPortal({ children, scene }) {
  return createPortal(children, scene)
}

applyProps

Sets properties on a three.js element using the same logic R3F uses internally:

jsx
import { applyProps } from '@react-three/fiber'

const mesh = new THREE.Mesh()
applyProps(mesh, { position: [1, 2, 3], 'material-color': 'hotpink' })

addEffect / addAfterEffect / addTail

Global render callbacks that run outside of any component:

jsx
import { addEffect, addAfterEffect, addTail } from '@react-three/fiber'

// Runs before every frame render
const removeEffect = addEffect(() => {
  // Do something before render
})

// Runs after every frame render
const removeAfterEffect = addAfterEffect(() => {
  // Do something after render
})

// Runs when the render loop stops
const removeTail = addTail(() => {
  // Do something when rendering stops
})

// Clean up by calling the returned function
removeEffect()

buildGraph

Collects nodes and materials from a THREE.Object3D into named collections:

jsx
import { buildGraph } from '@react-three/fiber'

const { nodes, materials } = buildGraph(object3D)