home

dt: 02/01/2025

How to Install and Try React Without a Framework

It can be quite bewildering to a beginner that the official React documentation doesn’t provide a straightforward way to install or try React without a framework. While there is a section explaining why you should use a framework, this can be daunting for someone who is just getting started or simply wants to dabble in React.

The official docs suggest adding React to an existing project using the following command:

npm install react react-dom

However, when you run this command, you may encounter an error due to a version conflict between React and the testing libraries, particularly @testing-library/react, which currently has a peer dependency on React 18.

To resolve this, you can either downgrade React or use the --legacy-peer-deps flag to bypass the peer dependency checks.

But how is all of this supposed to be understood by a beginner?

Here’s a simple and easy-to-follow approach for anyone who wants to install React without a framework. You can use Vite, a fast build tool, to quickly set up a React project:

Steps to Get Started with React Without a Framework:

  1. Create a new Vite project with the React template:
npm create vite@latest my-react-app -- --template react
  1. Navigate to your project directory:
cd my-react-app
  1. Install the necessary dependencies:
npm install
  1. Start the development server:
npm run dev

By following these simple steps, you’ll have a React app running without any framework, thanks to Vite.