What is React.js?
Features of React.js?
Virtual DOM: It is an in-memory data-structure cache. Only the most recent DOM updates have been modified in the browser’s DOM.
Pros and Cons of React.js
- Only the most recent changes are updated in the browser’s DOM by ReactJS, which uses a virtual DOM that uses an in-memory data-structure cache. This improves the app’s efficiency.
- Using the react component function, you can build components of your choosing. The modules are reusable and useful for code maintenance.
- React got popular in a short period of time, maintained by Facebook and Instagram. Since it is used by many well-known companies such as Apple, Netflix etc.
- ReactJS, the library, is managed by Facebook, so it is well-maintained and updated.
- It can be used to build both desktop and mobile apps with rich user interfaces.
- ReactJS has a wide file size.
How to install React?
Before installing React we have to install Node.js and NPM first. There are two ways of installing react
Step 1 : Open the command prompt (Using Windows+R keys) and type ‘cmd’ to open a run command box and click ‘OK’
Step 2 : Create a folder with name reactproject and type the following:
Then we can see the prompt indicate C:\Users\User\reactproject.
Step 3 : Create the package.json file using the following command
C:\Users\User\reactproject>npm init -y
"test": "echo \"Error: no test specified\" && exit 1"
We can skip the above commands if we skip -y option
Step 4 : Install React and react dom
C:\Users\User\reactproject>npm install react --save
C:\Users\User\reactproject>npm install react-dom --save
Step 1 : Open the command prompt (Using Windows+R keys) and type ‘cmd’ to open a run command box and click ‘OK’ and type the following
npm install -g create-react-app
Important fact : Make sure you’re in the desired directory/folder before running create-react-app, as this command will create the project folder in the current path.
Step 2 : To create the project and type the following
Then the entire process is automated and begins with creating a new React app folder for the project, then installs packages and dependencies. React, react-dom, and react-scripts are among the default packages.. It will only take a few minutes to complete the installation.
How to Run a React Project?
Use the cd reactproject command to direct to our folder
and then type the following to run the project:
Next a default browser will open and load the project