React Three Fiber VR tutorial: your first WebXR scene
By the Turbl team · · 9 min read
To build a React Three Fiber VR scene, you add the @react-three/xr package to a normal Fiber app. You create a store with createXRStore(), wrap the scene in an XR component, and call store.enterVR() from a button. This tutorial builds that scene, then adds a box you can grab, teleport movement and a test on a Meta Quest.
Many older tutorials use VRButton, Controllers and Hands. Those come from version 5 of @react-three/xr. Version 6 replaced them. This page uses only the version 6 API.
What you need
React Three Fiber is a React renderer for three.js, a JavaScript 3D library. You write the scene as React components. WebXR is the browser standard that connects a web page to a headset. If it is new to you, read what WebXR is first.
You need Node.js and basic React knowledge. Vite 8 requires Node.js 20.19 or newer, or 22.12 or newer. A headset helps but is not required, because the XR package ships with an emulator.
These are the versions this tutorial was checked against, as of 26 November 2026.
| Package | Version | What it does |
|---|---|---|
three | 0.187.0 | Draws the 3D scene |
@react-three/fiber | 9.8.2 | Lets you write three.js as React components |
@react-three/xr | 6.6.32 | Adds VR and AR sessions, controllers and hands |
@react-three/handle | 6.6.32 | Adds grab, rotate and scale interactions |
react | 19.3.1 | Fiber 9 pairs with React 19 |
vite | 8.4.0 | Dev server and build tool |
Fiber 8 pairs with React 18, and Fiber 9 pairs with React 19. The XR package accepts both pairs. Fiber 9.8.2 accepts React 19.0 up to 19.3, so check the pairing again when React 19.4 ships.
Step 1: create the Vite project
Vite is the build tool the XR documentation recommends. Create a React and TypeScript project. As of November 2026 the react-ts template installs React 19 and Vite 8.
npm create vite@latest my-vr-app -- --template react-ts
cd my-vr-app
npm install
npm install three @react-three/fiber @react-three/xr @react-three/handle
npm install -D @types/three @vitejs/plugin-basic-ssl
The last package matters. Browsers only expose WebXR on secure pages, which means HTTPS. @vitejs/plugin-basic-ssl gives the dev server a self-signed certificate. That is a certificate your own computer creates, so browsers show a warning before they load the page. Add the plugin to vite.config.ts:
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import basicSsl from '@vitejs/plugin-basic-ssl'
export default defineConfig({
plugins: [react(), basicSsl()],
})
Step 2: add the Canvas, the XR store and an Enter VR button
Three pieces turn a Fiber app into a VR app:
createXRStore()creates the store. It holds the session settings and the session state.XRwraps your scene and connects it to the store.store.enterVR()starts the session. Call it from a click, because browsers only start VR after a user action.
Replace src/App.tsx with this:
import { useState } from 'react'
import { Canvas } from '@react-three/fiber'
import { XR, createXRStore } from '@react-three/xr'
const store = createXRStore()
function ClickBox() {
const [red, setRed] = useState(false)
return (
<mesh
position={[-0.5, 1.2, -1]}
scale={0.3}
pointerEventsType={{ deny: 'grab' }}
onClick={() => setRed(!red)}
>
<boxGeometry />
<meshStandardMaterial color={red ? 'red' : 'blue'} />
</mesh>
)
}
export default function App() {
return (
<>
<button
style={{ position: 'fixed', top: 16, left: 16, zIndex: 1 }}
onClick={() => store.enterVR()}
>
Enter VR
</button>
<Canvas style={{ position: 'fixed', inset: 0 }}>
<XR store={store}>
<ambientLight intensity={1} />
<directionalLight position={[1, 3, 2]} intensity={2} />
<ClickBox />
</XR>
</Canvas>
</>
)
}
Units are meters. The box sits 1.2 meters up and 1 meter in front of you. In three.js, negative Z is forward.
The onClick handler is the same one Fiber uses for a mouse. In VR, the XR package fires it when you point a controller ray at the box and pull the trigger. With hand tracking, it also fires when you touch the box with your index finger. pointerEventsType={{ deny: 'grab' }} stops a grab from counting as a click.
You did not add controllers or hands. Version 6 adds them by default.
Step 3: make a box you can grab
Grabbing comes from a companion package, @react-three/handle. Wrap any object in Handle and the user can move, rotate and scale it.
Add two imports, and extend the XR import:
import { Handle } from '@react-three/handle'
import { XR, createXRStore, noEvents, PointerEvents } from '@react-three/xr'
Add the component:
function GrabBox() {
return (
<Handle>
<mesh position={[0.5, 1.2, -1]} scale={0.3}>
<boxGeometry />
<meshStandardMaterial color="orange" />
</mesh>
</Handle>
)
}
Then change the Canvas so it uses the XR package's event system, and render the box:
<Canvas events={noEvents} style={{ position: 'fixed', inset: 0 }}>
<PointerEvents />
<XR store={store}>
<ambientLight intensity={1} />
<directionalLight position={[1, 3, 2]} intensity={2} />
<ClickBox />
<GrabBox />
</XR>
</Canvas>
events={noEvents} turns off Fiber's built-in pointer events. PointerEvents turns on the ones from the XR package. The handle package's own example uses this pair, and it makes the same grab work with a mouse on a flat screen.
In the headset, reach into the orange box and squeeze the grip button to hold it. With hand tracking, pinch it. You can also grab it from a distance with the ray and the trigger. Grab it with both hands and pull them apart to scale it. This input mapping comes from the package source for version 6.6.32, not from a headset test.
Handle takes translate, rotate and scale props to limit what the user can do. For example, scale={false} disables scaling. Our guide to VR interaction design for grabbing covers how a grab should feel.
Step 4: add teleport
In VR you never move the camera yourself. The headset controls it. You move the origin instead, the point in your scene where the player's feet are. The XROrigin component sets it.
Teleport needs three changes. First, turn on the teleport pointer in the store:
const store = createXRStore({
controller: { teleportPointer: true },
hand: { teleportPointer: true },
})
Second, extend the imports:
import { Vector3 } from 'three'
import { XR, XROrigin, TeleportTarget, createXRStore, noEvents, PointerEvents } from '@react-three/xr'
Third, keep the player's position in state and add a floor that accepts teleports:
function Floor({ onTeleport }: { onTeleport: (point: Vector3) => void }) {
return (
<TeleportTarget onTeleport={onTeleport}>
<mesh scale={[10, 1, 10]} position={[0, -0.5, 0]}>
<boxGeometry />
<meshStandardMaterial color="green" />
</mesh>
</TeleportTarget>
)
}
Inside App, add the state. Then render the origin and the floor inside XR:
const [position, setPosition] = useState(new Vector3())
// inside <XR>
<XROrigin position={position} />
<Floor onTeleport={setPosition} />
The floor is a 10 by 10 meter box with its top at height zero. In the headset, a curved ray now comes out of each controller. Point it at the floor, then pull and release the trigger. You jump when you release. The ray only hits meshes inside a TeleportTarget.
Or move with the thumbstick
Some players prefer smooth movement. The package has a hook for it, useXRControllerLocomotion. Add useRef to the React import, Group to the three import and useXRControllerLocomotion to the XR import. Then replace the XROrigin line with this component:
function Player() {
const origin = useRef<Group>(null)
useXRControllerLocomotion(origin, { speed: 2 }, { type: 'snap', degrees: 45 }, 'left')
return <XROrigin ref={origin} />
}
The left thumbstick moves you. The right thumbstick turns you in 45 degree steps. The hook reads controllers only, so it does nothing with tracked hands. Render one XROrigin, not two.
Meta's locomotion guidelines say teleport helps people who are sensitive to motion sickness, because it removes continuous motion. Smooth movement is worth offering as an option. Our overview of VR locomotion types explains the trade-offs.
Step 5: test in the built-in emulator
Start the dev server:
npm run dev
Open https://localhost:5173 in a desktop browser. The browser warns about the self-signed certificate. Accept the warning.
The XR package bundles an emulator based on IWER, Meta's Immersive Web Emulation Runtime. It fakes a headset in the browser. It loads by itself when the host name is localhost and the browser has no WebXR support. 127.0.0.1 does not trigger it. By default it pretends to be a Meta Quest 3. If it does not appear, press Windows or Command, plus Alt or Option, plus E.
Click Enter VR. The emulator overlay lets you move the virtual headset and controllers. The documentation calls this emulator experimental. It tells you whether your logic works. It does not tell you how the scene feels or performs. For other options, see how to test WebXR without a headset.
One known conflict: version 1 of the Immersive Web Emulator browser extension is not supported. The documentation says to turn it off, because it blocks the built-in emulator.
Step 6: open it on a Meta Quest
There are two ways to reach your dev server from the headset.
Over Wi-Fi. Start Vite with the host flag:
npm run dev -- --host
Vite prints a network address, such as https://192.168.0.43:5173. Put the headset on the same Wi-Fi network. Type that address into the Meta Quest Browser, including https://. The browser shows the same certificate warning. Choose to proceed, then press Enter VR.
Over USB. This route needs developer mode on the headset and ADB on your computer. ADB is Android's command-line tool for talking to a device. Connect the cable and run:
adb devices
adb reverse tcp:5173 tcp:5173
The first command should list the headset with the status device. The second maps port 5173 on the headset to port 5173 on your computer. Now https://localhost:5173 in the Quest browser reaches your dev server. With the cable connected, open chrome://inspect/#devices in Chrome on your computer. You can inspect the headset tab there and read its console.
When Enter VR does nothing
These causes and fixes come from the XR documentation's FAQ.
| Symptom | Cause | Fix |
|---|---|---|
| Nothing happens on click | The page is not on HTTPS | Use the SSL plugin and an https:// address |
| Still nothing | The XR component is missing or not mounted yet | Put XR directly inside Canvas |
| Fails while models load | The scene is suspended, so XR is not mounted | Wrap the scene in Suspense inside XR |
| Camera position looks wrong | OrbitControls is overwriting the camera | Remove it in VR, or guard it with IfInSessionMode |
To leave VR from code, call store.getState().session?.end().
Where to go next
The XR documentation has tutorials for hit testing, anchors, object detection and custom controller models. Meta also publishes a longer sample, a target shooting game built with the same two libraries. It adds sound, haptics and scoring.
React Three Fiber is one of several ways to build for the headset browser. Our WebXR frameworks comparison sets it next to three.js, Babylon.js and A-Frame.
If you want a playable scene without writing the code, Turbl builds a WebXR project from a text description. It has limits. Projects are single player, and there is no APK or store export. If you want control over every component, write the code yourself as shown here.
FAQ
Does React Three Fiber support VR?
Yes, through the @react-three/xr package. It adds VR and AR sessions, controllers, hand tracking and teleport to a Fiber app. It works in WebXR browsers such as the Meta Quest Browser.
What replaced VRButton and Controllers in @react-three/xr?
Version 6 uses a store. You call createXRStore(), pass the store to an XR component, and call store.enterVR() from your own button. Controllers and hands are added by default. A compatibility layer still exports VRButton, but the documentation recommends moving away from it.
Do I need a VR headset to develop with React Three Fiber?
No. The XR package includes an emulator that loads on localhost when the browser has no WebXR support. You should still test on a real headset before you ship, because the emulator does not show comfort or performance.
Why does my VR scene need HTTPS?
Browsers only expose WebXR in secure contexts. A plain http:// address on your local network does not count, so a headset on Wi-Fi needs https://. http://localhost counts as secure on the machine that runs the server.
Does React Three Fiber VR work with WebGPU?
Not in a headset as of November 2026. Fiber 10 is in alpha and adds WebGPU support. The XR documentation says headsets do not yet implement WebGPU for WebXR, so VR sessions still use WebGL.
Does it work on iPhone or Apple Vision Pro?
The XR documentation says WebXR works in Safari on Apple Vision Pro. It also says iOS Safari does not support WebXR yet.
Sources
- Introduction to @react-three/xr, Poimandres
- Development setup, Poimandres
- Store options, Poimandres
- Interactions, Poimandres
- Teleportation, Poimandres
- Gamepad, Poimandres
- Migrate from @react-three/xr v5, Poimandres
- useXRControllerLocomotion, Poimandres
- Handles, Poimandres
- Handle component, Poimandres
- FAQ for @react-three/xr, Poimandres
- React Three Fiber introduction, Poimandres
- Getting started with Vite, Vite
- WebXR Device API, MDN
- Secure contexts, MDN
- Debug browser content, Meta
- WebXR first steps with React, Meta
- Locomotion types, Meta
- Immersive Web Emulation Runtime, Meta