Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • React Tutorial
  • React Exercise
  • React Basic Concepts
  • React Components
  • React Props
  • React Hooks
  • React Router
  • React Advanced
  • React Examples
  • React Interview Questions
  • React Projects
  • Next.js Tutorial
  • React Bootstrap
  • React Material UI
  • React Ant Design
  • React Desktop
  • React Rebass
  • React Blueprint
  • JavaScript
  • Web Technology
Open In App
Next Article:
How useMemo Hook optimizes performance in React Component ?
Next article icon

How to optimize the performance of React app ?

Last Updated : 04 Dec, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

The operations involved in keeping the DOM updates are costly but react uses several techniques to minimize the no. of operations which leads to natively faster UI for many cases.

The following techniques can be used to speed up the application:

Table of Content

  • Use binding functions in constructors
  • Avoid inline style attributes
  • Avoid extra tags by using React fragments
  • Avoid inline function in the render method
  • Avoid bundling all of the front end code in a single file

1. Use binding functions in constructors:

By adding an arrow function in a class, we add it as an object and not as the prototype property of the class. If we use the component multiple times, there will be various instances of these functions within each object of the component. The most reliable way to use functions is to bind them with the constructor.

2. Avoid inline style attributes:

The browser often invests a lot of time rendering, when styles are implied inline. Scripting and rendering take time because the browser has to plan all the React style rules to the CSS properties. Creating a separate style.js file and importing it into the component is a faster method.

Example: Creating a separate style.js file and importing in the component instead of using inline style attribute:

Javascript

import React from "react";
import styles from "./styles.css"
 
export default class StyleExample extends React.Component {
    render() {
        return (
            <>
                <h1>
                    GeeksforGeeks
                </h1>
            </>
        );
    }
}
                      
                       

CSS

h1{
    color: green;
    margin: 50;
}
                      
                       

Output:

3. Avoid extra tags by using React fragments:

Using react fragments decreases the no. of additional tags and satisfies the necessity of having a single parent element in the component.

Example: Using react fragments

javascript

import React from "react";
const App = () => {
    return (
        <div>
            <h1 style={{ color: "green", margin: 50 }}>
                GeeksforGeeks: react fragments as root element
            </h1>
        </div>
    );
};
export default App;
                      
                       

Output:

4. Avoid inline function in the render method:

If we use the inline function, the function will generate a new instance of the object in every render and there will be multiple instances of these functions which will lead to consuming more time in garbage collection. To optimize that we can define functions outside the render method and call them wherever required.

Example: Creating functions outside the render method

javascript

import React, { useState } from "react";
const App = () => {
    const [isClicked, setIsclicked] = useState(false);
    const handleClicked = () => {
        setIsclicked(true);
        console.log(`clicked ${isClicked}`);
    };
    return (
        <div style={{ margin: 50 }}>
            <h1 style={{ color: "green" }}>
                GeeksforGeeks: function outside render example
            </h1>
            <button onClick={handleClicked}>Click me!</button>
        </div>
    );
};
export default App;
                      
                       

Output:

5. Avoid bundling all of the front end code in a single file:

By splitting the files into resource and on-demand code files we can reduce the time consumed in presenting bundled files to the browser transformers.



Next Article
How useMemo Hook optimizes performance in React Component ?

S

swapnil074
Improve
Article Tags :
  • ReactJS
  • Web Technologies
  • React-Questions

Similar Reads

  • How to Optimize the Performance of React-Redux Applications?
    Optimizing the performance of React-Redux applications involves several strategies to improve loading speed, reduce unnecessary re-renders, and enhance user experience. In this article, we implement some optimization techniques, that can significantly improve the performance of applications. We will
    9 min read
  • How can you optimize the performance of React-Redux applications?
    Performance optimization in React-Redux involves improving the speed, efficiency, and responsiveness of applications by minimizing rendering times, reducing unnecessary re-renders, and optimizing data fetching and processing. By implementing optimization techniques, you can enhance the overall user
    5 min read
  • How to Optimize Vite Performance?
    Vite is a modern build tool invented by Evan You. It is designed for speed and provides the best UX. For today’s JavaScript projects, it has hot module replacement (HMR) and optimized builds. Still, if you want to achieve the maximum level of possible results, you can tweak several aspects of the wo
    5 min read
  • How to Optimize WebGL Performance?
    WebGL (Web Graphics Library) is a powerful JavaScript API used to render 3D and 2D graphics within any compatible web browser. However, achieving optimal performance with WebGL requires careful attention to various aspects of your code and rendering pipeline. Key strategies to optimize WebGL perform
    3 min read
  • How useMemo Hook optimizes performance in React Component ?
    The useMemo hook in React optimizes performance by memoizing the result of a function and caching it. This caching ensures that expensive computations inside the useMemo callback are only re-executed when the dependencies change, preventing unnecessary recalculations and improving the rendering perf
    2 min read
  • How memoization optimizes performance in React ?
    Have you ever wondered how computers can do complex tasks super fast? Well, memoization is like a secret trick that makes certain tasks much quicker by remembering past results instead of recalculating them every time. It's a game-changer for functions that do the same calculations over and over aga
    6 min read
  • Optimizing Performance in ReactJS
    Performance matters a lot in any application. In ReactJS, Optimizing the performance is an important task to do before launching a React application. There are different ways to explore optimizing a React application that can help to increase speed and efficiency as well as user experience.  ReactJS
    4 min read
  • Mastering Performance Optimization Techniques with React Hooks
    In this article, we will explore advanced performance optimization techniques using React Hooks. We'll delve into memoization, callback optimization, preventing unnecessary renders, state updates, and more. By mastering these techniques, developers can significantly enhance the performance of their
    6 min read
  • Performance Hooks in React
    While developing React Applications, optimizing performance is one of the most important things for delivering a seamless user experience. One common way to boost performance is to minimize unnecessary re-renders by skipping repetitive calculations. React provides two powerful hooks, useMemo and use
    3 min read
  • Optimizing Performance with useMemo and useCallback Hooks
    In React applications, optimizing performance is crucial for ensuring smooth user experiences, especially in components with complex computations or frequent re-renders. Two hooks provided by React, useMemo, and useCallback, offer efficient ways to achieve performance improvements by memoizing value
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences