Registry / 3d / react-babylonjs

react-babylonjs

JSON →
library4.0.2jsnpmunverified

Bridges React with Babylon.js 3D engine. Current version 4.0.2 (released 2024) requires Babylon.js >=8.32.0 and React 19. Fully typed with TypeScript, uses react-reconciler for declarative 3D scenes. Supports Hooks, Suspense, and concurrent mode. Key differentiator: full component tree integration vs imperative Babylon.js API.

npm install react-babylonjs
INSTALL
IMPORT
SIG · REACT-BABYLONJS
R
react-babylonjs
3djavascriptv4.0.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Engine
import { Engine } from 'react-babylonjs'
const Engine = require('react-babylonjs').Engine
ESM-only since v3; named export
Scene
import { Scene } from 'react-babylonjs'
Named export, not default
useBeforeRender
import { useBeforeRender } from 'react-babylonjs/hooks'
import { useBeforeRender } from 'react-babylonjs'
Hooks are in a separate subpath 'react-babylonjs/hooks' since v4.0.0
WithScene
import { WithScene } from 'react-babylonjs'
HOC named export
NullableEngine
import type { NullableEngine } from 'react-babylonjs'
Type import for engine reference

Minimal 3D scene with camera, light, ground, and rotating box using declarative React-Babylonjs.

import React from 'react'; import { createRoot } from 'react-dom/client'; import { Engine, Scene } from 'react-babylonjs'; import { Vector3, Color3, HemisphericLight, MeshBuilder } from '@babylonjs/core'; function App() { return ( <Engine antialias={true} adaptToDeviceRatio={true} canvasId='babylon-canvas'> <Scene> <freeCamera name='camera' position={new Vector3(0, 5, -10)} target={Vector3.Zero()} /> <HemisphericLight name='light' intensity={0.7} direction={Vector3.Up()} /> <ground name='ground' width={6} height={6} /> <box name='box' size={2} position={new Vector3(0, 1, 0)} /> </Scene> </Engine> ); } const container = document.getElementById('root'); const root = createRoot(container!); root.render(<App />);
Debug
Known issues
breakingMigrated from default export to named exports in v3.0.0
fix
Use import { Engine, Scene } from 'react-babylonjs' instead of import Babylon from 'react-babylonjs'.
affects: >=3.0.0
breakingHooks moved to 'react-babylonjs/hooks' subpath in v4.0.0
fix
Use import { useBeforeRender } from 'react-babylonjs/hooks' instead of 'react-babylonjs'.
affects: >=4.0.0
breakingRequires React 19 as of v4.0.0; incompatible with React 18
fix
Upgrade React to 19 or use react-babylonjs v3 with React 18.
affects: >=4.0.0
deprecatedFreeCamera, ArcRotateCamera are deprecated; use <freeCamera> and <arcRotateCamera> components
fix
Use lowercase component names without 'Camera' suffix, e.g., <freeCamera> instead of <FreeCamera>.
affects: >=3.2.0
Errors
Common errors & fixes
The engine already has a running scene (or scene is null)
Engine component not rendered or multiple Engine instances
fix
Check that only one <Engine> component is mounted and that a canvas with the given id exists.
Cannot use 'useBeforeRender' outside of a Scene component
Hooks must be called inside a <Scene> component tree
fix
Wrap the component in a <Scene>.
Module not found: Can't resolve 'react-babylonjs/hooks'
Using v3 which does not have the hooks subpath
fix
Upgrade to v4 or import from 'react-babylonjs'.
TypeError: Cannot read properties of undefined (reading 'getEngine')
Accessing Babylon API before engine initializes
fix
Use useBeforeRender or await setup.
Upgrade
Version history
4.0.2latest on npm
Audit
Dependencies
@babylonjs/corerequiredCore Babylon.js engine
@babylonjs/guioptionalBabylon.js GUI system
reactrequiredPeer dependency for React integration
react-domrequiredPeer dependency for React DOM rendering
Agent activity
4 hits · last 30 days
node
4
Resources
react-babylonjs — npm install react-babylonjs · libregistry