The Wayback Machine - https://web.archive.org/web/20241001004215/https://www.geeksforgeeks.org/reactjs-introduction/
Open In App

React Introduction

Last Updated : 11 Mar, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

ReactJS, also known as React, is a popular JavaScript library for building user interfaces. It is also referred to as a front-end JavaScript library. It was developed by Facebook and is widely used for creating dynamic and interactive web applications. In this article, we’ll explore the key concepts of React.

Lightbox

‍What is React ?

React is a JavaScript library for building user interfaces (UIs) on the web. React is a declarative, component based library that allows developers to build reusable UI components and It follows the Virtual DOM (Document Object Model) approach, which optimizes rendering performance by minimizing DOM updates. React is fast and works well with other tools and libraries.

Prerequisite of React

For learning React first you have a clear understanding of HTML, CSS and JavaScript. As React is a JavaScript library and uses most of its concept so you really have to understands the major concepts of it.

History of React

  • React was invented by Facebook developers who found the traditional DOM slow. By implementing a virtual DOM, React addressed this issue and gained popularity rapidly.
  • The current stable version of ReactJS is 18.2.0, released on June 14, 2022. The library continues to evolve, introducing new features with each update.

How does React work?

React operates by creating an in-memory virtual DOM rather than directly manipulating the browser’s DOM. It performs necessary manipulations within this virtual representation before applying changes to the actual browser DOM. React is efficient, altering only what requires modification.

Browser-DOM-Virtual-DOM

Features of React

React is one of the most demanding JavaScript librarys because it is equipped with a ton of features which makes it faster and production-ready. Below are the few features of React.

1. Component-Based Architecture

React provides the feature to break down the UI into smaller, self-contained components. Each component can have its own state and props.

2. JSX (JavaScript Syntax Extension)

JSX is a syntax extension for JavaScript that allows developers to write HTML-like code within their JavaScript files. It makes React components more readable and expressive.

const name="GeekforGeeks";
const ele = <h1>Welcome to {name}</h1>;


3. Virtual DOM

React maintains a lightweight representation of the actual DOM in memory. When changes occur, React efficiently updates only the necessary parts of the DOM.

sd

4. One-way Data Binding

One-way data binding, the name itself says that it is a one-direction flow. The data in react flows only in one direction i.e. the data is transferred from top to bottom i.e. from parent components to child components. The properties(props) in the child component cannot return the data to its parent component but it can have communication with the parent components to modify the states according to the provided inputs.

5. Performance

As we discussed earlier, react uses virtual DOM and updates only the modified parts. So , this makes the DOM to run faster. DOM executes in memory so we can create separate components which makes the DOM run faster.

6. Components

React divides the web page into multiple components as it is component-based. Each component is a part of the UI design which has its own logic and design as shown in the below image. So the component logic which is written in JavaScript makes it easy and run faster and can be reusable.

7. Single-Page Applications (SPAs)

React is recommended in creating SPAs, allowing smooth content updates without page reloads. Its focus on reusable components makes it ideal for real-time applications.

ReactJS Lifecycle

Every React Component has a lifecycle of its own, lifecycle of a component can be defined as the series of methods that are invoked in different stages of the component’s existence. React automatically calls these methods at different points in a component’s life cycle. Understanding these phases helps manage state, perform side effects, and optimize components effectively.

1. Initialization

This is the stage where the component is constructed with the given Props and default state. This is done in the constructor of a Component Class.

2. Mounting Phase

  • Constructor: The constructor method initializes the component. It’s where you set up initial state and bind event handlers.
  • render(): This method returns the JSX representation of the component. It’s called during initial rendering and subsequent updates.
  • componentDidMount(): After the component is inserted into the DOM, this method is invoked. Use it for side effects like data fetching or setting timers.

3. Updating Phase

  • componentDidUpdate(prevProps, prevState): Called after the component updates due to new props or state changes. Handle side effects here.
  • shouldComponentUpdate(nextProps, nextState): Determines if the component should re-render. Optimize performance by customizing this method.
  • render(): Again, the render() method reflects changes in state or props during updates.

4. Unmounting Phase

  • componentWillUnmount(): Invoked just before the component is removed from the DOM. Clean up resources (e.g., event listeners, timers).

FAQs on React

Is React a framework or library?

It is very confusing to a lot of people that if React is a framework of a library. React is considered as a library rather than a framework. While in the framework there is a controlled way of structure to write the code whether in library you are free to write without any structural restriction.

How do I Start Learning React?

React has a large community that keeps updating all the concepts of React. You just need to follow proper step by step roadmap to learn React and keep hands on practice on it.

You can follow our React Tutorial that covers all the topics of React from basic to pro in step wise manner.

What is JSX?

JSX, which stands for JavaScript XML, is a syntax extension for JavaScript. ReactJS uses an XML or HTML-like syntax, which is then transformed into React Framework JavaScript calls. Essentially, JSX expands ES6 to allow HTML-like text to coexist with JavaScript React code. Although it is not mandatory to use JSX in ReactJS, it is highly recommended.

Syntax:

const example = “JSX”
const ele = <div>This component uses {example} </div>

Is React Beginner Friendly?

Yes, React is very simple and beginner friendly. It just uses JavaScript and JSX to create the Single page Application. If you have the basic knowledge of HTML, CSS and JavaScript you are good to go to dive deep into the React world.



    Previous Article
    Next Article

    Similar Reads

    Introduction to React Native
    If you want to build mobile apps for both Android and iOS. What should you learn? The individual native languages for each app i.e, Java for Android and Swift/Objective-C for iOS?, Actually NO. Native Android and iOS development are quite different and can be expensive – first, the language itself is quite different, and second, all the underlying
    3 min read
    Introduction to React-Redux
    The ones familiar with react will know that react is a component-based front end library tool that connects the various segments of the web page. In react, we use props (short for properties) in a component which allows the usage of non-static variables. With the help of props, we can pass these variables into various other components (child compon
    5 min read
    React Desktop Introduction
    React Desktop is a popular library to bring the native desktop experience to the web. This library provides macOS and Windows OS components. It is a cross-platform desktop development library. It is also compatible with electron.js and NW.js. It is mostly used in javascript-powered projects. Installation Steps of React Desktop: Step 1: Create a Rea
    2 min read
    React Rebass Introduction
    React Rebass is a front-end framework that was designed keeping react in mind. React Rebass is built with a Styled System. It is the best choice to create prototypes and UI without needing to invest time in building a custom design system up-front. React Rebass provides us with flexible components. Installation: You can install Rebass with the help
    2 min read
    React Suite Introduction
    React Suite is a popular front-end library with a set of React components that are designed for the middle platform and back-end products. It is a developer-friendly UI framework. Installation: You can install it with the following command: npm i rsuite // or yarn add rsuite Now you can import suite components like: import { Button } from 'rsuite';
    3 min read
    React Spring Introduction and Installation
    React Spring is an animation library that makes animating UI elements simple. It is different from other animation libraries where someone has to deal with curves, easing, and time durations, all of which are in sync with each other. Platforms: React Spring is a cross-platform library, it supports React, react-native, web, and many more platforms.
    2 min read
    React Material-UI Introduction and Installation
    Material UI is the most powerful and efficient React UI Framework to build an Application by adding Designs and Animations and using it with technical and scientific innovation. It is basically a design language that was developed by Google in 2014. It uses more Design and Animations, grid-system and provides shadows and lightning effects. Material
    2 min read
    Introduction to React Hooks
    In React, Hooks are functions that allow you to manage state and perform side effects without the involvement of class components. Hooks were introduced in v16.8 of React and they can be accessed only through functional components but not through class components (Hooks were specifically designed for that). Hooks allow you to "hook into" React stat
    7 min read
    React-Motion Introduction & Installation
    The react-motion package is a JavaScript animation library for the React applications which can be used for creating smooth and interactive animations. This uses the spring-based physics model, through which we can define animations with natural and dynamic movements. This library is mainly suited for complex UI animations and transitions. In this
    4 min read
    React Bootstrap Introduction
    The most popular CSS framework for responsive layouts is Bootstrap. This open-source toolkit includes Sass variables, a responsive grid framework, and a large number of JavaScript plugins. It has now been redesigned in React so that it can work with React apps. Bootstrap 4 relies on jQuery, however, jQuery isn't ideal for React because it manipulat
    4 min read
    Fluent UI Introduction and Installation for React
    Microsoft's Fluent UI, unveiled in 2017, is an open-source, cross-platform design system that empowers developers to craft seamless applications like Office 365. It guarantees a uniform and polished design across diverse platforms for a cohesive user experience. Prerequisite:Node JS React JSFeatures of Fluent UI:Highly customizable.Up to date compo
    2 min read
    Introduction and Installation of Storybook for React
    Storybook is an open-source UI development tool that facilitates the creation of reusable, well-documented components independently. It automates visual testing to prevent bugs and runs alongside the app in development mode. Additionally, it supports server-rendered component frameworks like Ruby on Rails. Prerequisites:NodeJS or NPMReact JSStorybo
    2 min read
    Create a Card View in React native using react-native-paper
    React Native is a framework developed by Facebook for creating native-style apps for iOS & Android under one common language, JavaScript. Initially, Facebook only developed React Native to support iOS. However, with its recent support of the Android operating system, the library can now render mobile UIs for both platforms. Approach: In this ar
    2 min read
    Create an Activity Indicator in react-native using react-native-paper library
    React Native is a framework developed by Facebook for creating native-style apps for iOS & Android under one common language, JavaScript. Initially, Facebook only developed React Native to support iOS. However, with its recent support of the Android operating system, the library can now render mobile UIs for both platforms. Prerequisites: Basic
    2 min read
    React Suite Icon extension React Icons
    A React suite is a library of React components, sensible UI design, and a friendly development experience. It is supported in all major browsers. It provides pre-built components of React which can be used easily in any web application. In this article, we'll learn about React Suite Icon extension React icons. React Icons, contains various popular
    3 min read
    How to Add MUI React Button Icon in React-Bootstrap ?
    In this article, we will learn how to add the mui react button icon in react-bootstrap. Icons can be added in the react-bootstrap by importing the MUI icon component and using it within your React-Bootstrap button. React-Bootstrap is a front-end framework that was designed keeping React in mind. Steps to Create React Application And Installing Modu
    2 min read
    How to import from React-Select CDN with React and Babel ?
    In ReactJS, import from React-Select CDN is not done in a simple way as we do with the npm packages. To use them we need to use directly them in the HTML file. It does not work with the project set-up by creating a react app. Prerequisites:React JSHTML, CSS, JavaScriptSteps to Import React-Select CDN with React and Babel:Step 1: Create index.html w
    2 min read
    Explain new features of React Memo in React v16.6 ?
    React memo is a Higher Order Component (HOC) introduced in React v16.6. As the name suggests, Memo API uses the memoization technique to optimize performance and make the application faster. The Memo API avoids unnecessary re-renders in functional components thereby optimizing the performance of the application. We will see two different examples m
    2 min read
    What is the difference between react-fetch and whatwg-fetch in React.js ?
    React-fetch and Whatwg-fetch are both libraries for making HTTP requests in a React application, but they are used for different purposes and have different features. Table of Content React-fetchWhatwg-fetchDifference between React-fetch and Whatwg-fetchReact-fetch: `react-fetch` is a library offering a higher-order component (HOC) for streamlined
    2 min read
    Plugin "react" was conflicted between "package.json » eslint-config-react-app
    The error Plugin "react" was conflicted between package.json and eslint-config-react-app generally arises when there is a conflict in naming convention or package.json data. However, this is not the only reason for this conflict. Some of the other reasons can be due to a different version or conflict in project dependencies. Error image from Termin
    2 min read
    How to Zoom in/Zoom out using React-PDF in React JS ?
    Zooming in or out in React-PDF within a React JS application is achieved by using the 'scale' prop inside the `<Page />` component. The 'scale' prop accepts decimal values; values greater than 1 zoom in, while values less than 1 zoom out the page. Prerequisites:React JSReact Functional ComponentsSyntax: <page scale = {value} /> // When
    2 min read
    Why to use React Hooks Instead of Classes in React JS ?
    The introduction of React Hooks has changed the way we are managing states and lifecycle features. They offer more easy and functional way as compared to class based components. In this article, we will learn why to use React Hooks Instead of Classes in ReactJS, but lets first discuss about both React hooks and class based components. Table of Cont
    4 min read
    What are React Hooks, and why were they added to React?
    React Hooks are a way to add functionality to functional components in React. Before Hooks, functional components were more limited compared to class components in terms of what they could do. With Hooks, users can now use state, lifecycle methods, and other React features in functional components, making them more powerful and flexible. Hooks Addr
    2 min read
    Difference between React.memo() and useMemo() in React.
    In React applications, optimizing performance is crucial for delivering a smooth user experience. Two key tools for achieving this are React.memo() and useMemo(). While both help improve performance, they serve different purposes and are used in distinct scenarios. Table of Content What is React.memo() ?What is useMemo() ?Difference Between React.m
    3 min read
    How does React.memo() optimize functional components in React?
    React.memo() is a higher-order component provided by React that can help optimize functional components by reducing unnecessary re-renders. Let's explore how it works and how it optimizes functional components: Table of Content Optimizing with React.memo()When to use React.memo() ?Benefits of memoization using React.memo()How to use React.memo() ?C
    4 min read
    How to add a divider in react-native using react-native-paper library ?
    React native is a framework developed by Facebook for creating native-style apps for iOS & Android under one common language, JavaScript. Initially, Facebook only developed React Native to support iOS. However, with its recent support of the Android operating system, the library can now render mobile UI's for both platforms. Prerequisites: Basi
    2 min read
    How does React Router handle navigation in a React application?
    React Router is a standard library for routing in React. It enables the navigation among views of various components in a React Application, allows changing the browser URL, and keeps the UI in sync with the URL. Let us create a simple application to React to understand how the React Router works React Router simplifies navigation in React applicat
    3 min read
    What is the use of React Context in React-Redux?
    React Context is a feature that React provides us to manage states required in multiple components. Redux is also a state management library and solves the same problem that React Context does but in a different way. In this article, we will see in detail what is react context, why and how to use it, how it is related to and different from react-re
    5 min read
    Implementing React Router with Redux in React
    This article explores implementing React Router with Redux for enhanced state management and routing in React applications. Table of Content What is React Router and Redux?Approach to implement React Router in ReduxSteps to Setup the React AppWhat is React Router and Redux?React Router facilitates routing in React apps, managing component rendering
    3 min read
    Implementation of React.memo() and useMemo() in React
    React.memo allows functional component to have same optimization as Pure Component provides for class-based components. useMemo is for memoizing function's calls inside functional component. What is React.memo() ?React.memo() is a higher-order component (HOC) provided by React that memoizes functional components. It means that it caches the result
    3 min read