DREI & Helper Libraries

Back to Modules

@react-three/drei and Helper Libraries

While React Three Fiber (R3F) provides the core bridge between React and Three.js, @react-three/drei (often simply referred to as Drei) is an indispensable collection of helpful utilities and abstractions that significantly simplify common tasks in 3D scene creation. It's a vital part of the R3F ecosystem, offering ready-made components and hooks that save development time and effort.

What is @react-three/drei?

Drei is a growing library that provides a vast array of components and hooks built on top of R3F. It aims to make working with R3F more efficient by offering pre-built solutions for frequently used functionalities, allowing developers to focus on unique aspects of their 3D applications rather than re-implementing common patterns.

Categories of Helpers Provided by Drei:

Why Use Drei?

Example: Using <OrbitControls> and <Text> from Drei

This example demonstrates how to use <OrbitControls> for camera interaction and <Text> to display 3D text. Note that this requires a React environment to run.

import React from 'react';
import { Canvas } from '@react-three/fiber';
import { OrbitControls, Text } from '@react-three/drei';

function SceneWithDrei() {
  return (
    <Canvas>
      <ambientLight />
      <pointLight position={[10, 10, 10]} />

      <mesh>
        <boxGeometry args={[1, 1, 1]} />
        <meshStandardMaterial color="orange" />
      </mesh>

      <Text
        position={[0, 1.5, 0]}
        fontSize={0.5}
        color="white"
        anchorX="center"
        anchorY="middle"
      >
        Hello Drei!
      </Text>

      <OrbitControls />
    </Canvas>
  );
}

export default SceneWithDrei;