...

/

Using Three.js and React with TypeScript

Using Three.js and React with TypeScript

Learn how to create a React project with TypeScript and add Three.js scene to it.

We'll cover the following...

Let’s go a step further and see how we can integrate Three.js with React.

There are different ways of creating a React application from scratch (Vite, for instance, also supports this), but the most common way is to use the yarn create react-app lts-tf --template TypeScript command from the command-line. Just like with Vite, this will create a new project. For this example, we’ve created this project in the lts-tf directory. Once created, we have to add the Three.js libraries just like we did for Vite:

Press + to interact
yarn create react-app lts-tf --template typescript
cd lts-tf
yarn add three
yarn add -D @types/three

This should set up a simple react TypeScript application, add the correct Three.js libraries, and install all the other required modules. The next step is to quickly check if all this works. Run ...