React App Setup Guide
Create React App is an officially supported way to create single-page React applications. It offers a modern build setup with no configuration.
To install React:
- With Yarn:
yarn add react react-dom
- With npm:
npm install --save react react-dom
Setting up a New React App
When you create a new app, use npm or Yarn to install dependencies, depending on your tool to run create-react-app.
bash
npx create-react-app my-app
yarn create react-app my-app
Using Yarn in React Projects
Yarn installation is foundational for Yarn and React integration, as Yarn builds upon npm. Utilizing Yarn in React projects enhances dependency management efficiency and reliability compared to npm.
Tutorial Steps
- Install create-react-app globally
- Create a new React app project
- Use Yarn to manage dependencies
First, install create-react-app globally:
bash
yarn global add create-react-app
Then create a new React app:
bash
yarn create react-app my-app
Managing React Packages with Yarn
How to install React packages using yarn?
To install Yarn globally:
bash
npm install -g yarn
Create a new React project with:
bash
yarn create react-app my-app
To add dependencies:
yarn add package-name
yarn add [email protected]
yarn add package-name@tag
When you run yarn, it creates yarn.lock
tracking exact package versions installed. Add this file to version control for consistency across environments.
Additional Information
Yarn is faster, more secure, and more reliable than npm. It executes install tasks in parallel, increasing speed, and fully caches packages for offline installs.
The equivalent of npm install
is:
bash
yarn
Identify why a package is installed:
bash
yarn why package-name
Note: Use Ctrl+C to stop Yarn installation issues.