How to create a ThreeJS responsive ReactJS project

A step by step guide on creating a 3JS ReactJS project that updates its scene as the screen scales.

Oscar de la Hera Gomez
Written by Oscar de la Hera Gomez
First published on 11/06/2023 at 08:25
Last Updated on 03/17/2024 at 12:31
<p>Two flowers that represent ReactJS and ThreeJS side by side. Beneath them sits the text "ReactJS &amp; ThreeJS Responsive Starter Project."</p>

A step by step guide on creating a 3JS ReactJS project that updates its scene as the screen scales.

SubscribeDownload Open Source Starter Project

We recommend that you clone our Open Source React-Redux Starter Project, checking out the main branch and carrying out the steps below. The changes can be found on the tutorial/three-js/starter branch.

git clone git@github.com:delasign/react-redux-starter-project.git
View Repository

Please note that the repository has been setup to work with React Redux.

To learn how we did this, please consult the tutorial linked below.

Typescript & React Redux: A Quick Setup Guide (2022)

Please note that if you are seeking to use GLSL shaders we strongly recommend that you upgrade to a ReactJS project that uses ViteJS.

How to create a React, Typescript & ThreeJS GLSL Vite Project

Step One: Install the Dependencies

<p>A screenshot of Terminal showing us running the line of code detailed below.</p>

Open Terminal and set the current directory to that of the project.

Subsequently, add the Three JS dependency and its types using the line below:

yarn add three; yarn add @types/three;
Consult Three on NPM Packages

Step Two: Create the Scene

<p>A screenshot of VSCode showing the code for the ThreeJS scene. The code is found below.</p>

Create a new typescript file called Scene.tsx and paste in the code below.

We recommend that you create this scene component under a Components/3JS folder.

Step Three: Add the Scene to the App

<p>A screenshot of VSCode showing how we added the scene to the ReactJS app.</p>

Add the scene to the render function of the App.tsx file.

Step Four: Test

<p>A screenshot of the app running in a browser. If you change the scale of the screen, the object will adapt accordingly.</p>

Run the project and confirm that the scene works as expected.

Looking to learn more about ReactJS and ThreeJS ?

Search our blog to find educational content on learning how to use ReactJS and ThreeJS.

Search our BlogReact, ThreeJS & GLSL Resources

Any Questions?

We are actively looking for feedback on how to improve this resource. Please send us a note to inquiries@delasign.com with any thoughts or feedback you may have.
SubscribeContact UsVisit our BlogView our ServicesView our Work

Partner with us

We would love to get to know you and see how we can help your organization with its goals and needs.
Let's Talk

Stay Informed

Get occasional updates about our company, research, and product launches.
Subscribe