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:
npm create vite@latest my-react-app -- --template react
cd my-react-app
npm install
npm run dev
By following these simple steps, you’ll have a React app running without any framework, thanks to Vite.