icon

Learn Hub


Home   HTML   Css   JavaScript   React.js   C   C++   Python   MySQL   Java   Swift            

React.js-icon

React Js


React Introduction


What is React.js?

React, sometimes referred to as a frontend JavaScript framework, is a JavaScript library created by Facebook. React is a tool for building UI components.


How does React Work?

👉 React creates a VIRTUAL DOM in memory. 👉 React only changes what needs to be changed!

React.js History



React Getting Started



To use React in production, you need npm which is included with Node.js.
  1. To get an overview of what React is, you can write React code directly in HTML.
  2. But in order to use React in production, you need npm and Node.js installed.

Setting up a React Environment

If you have npx and Node.js installed, you can create a React application by using create-react-app.

  1. If you've previously installed create-react-app globally, it is recommended that you uninstall the package to ensure npx always uses the latest version of create-react-app.
  2. To uninstall, run this command: npm uninstall -g create-react-app.

Run this command to create a React application named my-react-app:

| npx create-react-app my-react-app

The create-react-app will set up everything you need to run a React application.


Run the React Application

| cd my-react-app

Run this command to run the React application my-react-app:

| npm start

A new browser window will pop up with your newly created React App! If not, open your browser and type localhost:3000 in the address bar.



React Features




Why Use React?


React is used for building large-scale applications with dynamic data changes. Here are some reasons why React is popular:



React Ecosystem




React Component Types


Functional Components

These are simple JavaScript functions that accept props as an argument and return React elements.

Class Components

These are ES6 classes that extend from React.Component and have a render method which returns React elements.


Stateful vs Stateless Components



React Lifecycle Methods


React lifecycle methods can be used inside class components (before React 16.8). They allow developers to hook into the different phases (mounting, updating, and unmounting) of a component.

React-Lifecycle-methods

React lifecycle methods



React vs Other Frameworks


React vs Angular

Angular is a full-fledged MVC framework, while React is a library that deals with the view component of MVC. Angular uses two-way data binding, whereas React promotes one-way data binding. Angular has a steep learning curve due to its comprehensive nature, whereas React is easier to learn and integrate into projects.

React vs Vue

Vue is similar to React in that it's also a view library, but it is more opinionated with a lot of features built-in, making it a more comprehensive solution out of the box. Vue uses a template-based syntax, whereas React uses JSX, which blends HTML and JavaScript.



Advanced React Concepts


Higher-Order Components (HOC)

A Higher-Order Component is a function that takes a component and returns a new component. HOCs are used to add additional functionality to existing components.

Render Props

Render props is a technique for sharing code between React components using a prop whose value is a function.

Context API

The Context API allows you to share state across the entire app (or part of it) lightly and with ease. It is a good alternative to prop drilling.


icon Learn more concepts icon