Menu

  • Home
  • Trending

CATEGORIES

  • Stock Market & Trading
  • Banking & Finance
    • Banking
    • Credit and Debit Cards
  • Business & Startups
    • Business Basics
    • Business ideas
  • Cooking & Food
    • Easy Healthy Meals
  • Education
    • Business Skills
    • Content Writing Skills
    • Digital Marketing
  • Fashion & Lifestyle
    • Fashion
  • Freelancing
    • Finance & Accounting
  • Health & Fitness
    • Health
    • Health care
    • Health care occupations
    • Health sciences
    • Human pregnancy
  • Hobbies
    • Entertainment
    • Environmental design
    • Handicrafts
    • Hobbies
    • Home appliances
    • Home improvement
    • Horticulture and gardening
  • Learn & Earn
  • Learners Hub
    • NFT Beginners
  • Movie
  • Music
    • Musical instruments
  • News
    • Nation Wants to Know
    • National News
  • Personal Development
    • Marriage
    • Parenting
    • Personal care and service occupations
    • Personal development
    • Personal life
  • Real Estate
  • Religion
    • Prayer Method
    • Puran
    • Sanatan Dharma Basic
    • Sanatan Dharma Symbols & meaning
    • Scienfic reason behind Sanatan Dharma
  • Social Media
  • Technology
    • Services & Software
    • Software development
    • Technology News
  • Travel & Tourism
    • Things to Do
    • Travel Blogs

Subscriptions

  • admin

Recent News

  • Kyosho 1/8 Inferno MP9 TKI4 V2 .21 Nitro Powered 4WD Buggy Readyset « Big Squid RC – RC Car and Truck News, Reviews, Videos, and More!
  • Adam Driver-starrer action-thriller 65 to release in India on March 10
  • Class Action Suit – Explained
  • Home
  • Browse
    • Personal Development
    • Fashion & Lifestyle
    • Health & Fitness
    • Cooking & Food
    • Stock Market & Trading
    • Business & Startups
    • Technology
    • Travel & Tourism
    • Business
    • Freelancing
    • Learners Hub
  • Refer & Earn
  • Blogs
No Result
View All Result
  • Login
No Result
View All Result
  • Feedback/Suggestions
  • About Us
  • Contact Us
Home Education Web Development skills

5 Tips for Optimizing Your React App’s Performance

admin by admin
January 25, 2023
in Web Development skills
0 0
0
Cryptocurrencies With Incredibly High Market Caps
0
SHARES
0
VIEWS
Share on FacebookShare on Twitter

One of the most frustrating things as a React developer is investing time and effort into building an application only to find it slow and unresponsive.

In this post, we’ll go over five tips to improve the performance of your React app.

1. Reduce Unnecessary Renders

Unnecessary re-renders can slow down your apps, making them feel sluggish and unresponsive.

By leveraging some of React’s built-in hooks, we can keep unnecessary renders at a minimum.

React.Memo

In React, components will re-render when state or prop values change. This also applies to child components where props might remain the same, but the parent component’s props change.

In this case, we can use React.memo(), a higher-order component to cache the output of the child component. Now the child component will be rendered only when its props change. This can be very useful for components that have many props that do not change frequently.

const myComponent = React.memo((props) => {
    /* render using props */
});

export default myComponent;

You can find the React documentation on how to use React memo here.

useCallback

useCallback Will return a memo-ized version of the callback that only changes if one of the dependencies has changed. This is useful when passing callbacks to optimized child components that rely on reference equality to prevent unnecessary renders.

const memoizedCallback = useCallback(
  () => {
    doSomething(a, b);
  },
  [a, b],
);

2. Lazy Loading With Code Splitting

As your app grows larger with third-party libraries and more functionality, so will your app’s bundle. This, in turn, will increase the load time of your app.

To combat this, we can split the bundle and only load what is currently needed. In React, this can be done by dynamically importing components with the React.lazy function.

Before:

import OtherComponent from './OtherComponent';

After:

const OtherComponent = React.lazy(() => import('./OtherComponent'));

This will automatically load the bundle containing the OtherComponent when this component is first rendered.

The lazy component should then be rendered inside a Suspense component, which allows us to show some fallback content (such as a loading indicator) while we’re waiting for the lazy component to load.

import React, { Suspense } from 'react';

const OtherComponent = React.lazy(() => import('./OtherComponent'));

function MyComponent() {
  return (
    <div>
      <Suspense fallback={<div>Loading...</div>}>
        <OtherComponent />
      </Suspense>
    </div>
  );
}

You can find the complete docs on code splitting here.

3. Debouncing and Throttling Event Actions

Debouncing is a technique used to improve the performance of frequently executed actions by delaying them, grouping them, and only executing the last call. For example, if you have a search field where results are queried as you are typing, making API calls for each keystroke would be extremely inefficient since we only care about the final result. In this case, a debounce function would be extremely useful, essentially only calling the search API after a pre-determined timeout.

Throttling or rate limiting is a technique used to improve the performance of frequently executed actions by limiting the rate of execution. It is similar to debouncing, except it guarantees the regular execution of an action. This is most useful for high-frequency event actions like resizing and scrolling, which cause React components to re-render. Since we don’t need to keep these actions 100% in sync, we can call the handlers of these events intermittently.

You can learn more about throttling and debouncing components here.

4. Virtualize Long Lists

If you need to display a large table or list that contains many rows, loading every single item on the list can significantly affect performance.

List virtualization, or “windowing,” is the concept of only rendering what is visible to the user. The number of elements that are rendered at first is a small subset of the entire list, and the “window” of visible content moves when the user continues to scroll. This improves both the rendering and scrolling performance of the list.

You can use the react-window library to start virtualizing lists in your app.

5. Optimizing Your Images

Although it may seem obvious, large images can significantly impact your app’s performance. From poor load times to sluggish performance, there are clear demerits to non-optimized large images. To avoid these performance penalties, you can compress them, resize them, and serve them in an appropriate format (such as webp). The best way to do this is using an image CDN service which will automate the step of optimizing the images it serves.

Conclusion

Poor app performance can reduce user engagement and negatively affect SEO. By following these tips, you will be able to improve performance with debouncing, throttling, and virtualizing long lists, prevent unnecessary re-renders with React.memo, and add general improvements to your app’s speed by optimizing images.



Source link

Tags: appsoptimizingPerformancereacttips

Latest News

  • Trending
  • Comments
  • Latest
Cryptocurrencies With Incredibly High Market Caps

Iravin Nizhal Box Office Collection Day 3 Worldwide & Budget

July 17, 2022
Celebrity couple Riteish Deshmukh, Genelia D’Souza buys BMW iX electric SUV worth Rs 1.16 crore | Electric Vehicles News

Celebrity couple Riteish Deshmukh, Genelia D’Souza buys BMW iX electric SUV worth Rs 1.16 crore | Electric Vehicles News

September 1, 2022
2022 TVS Ronin Launched; Prices Start At Rs. 1.49 lakh

2022 TVS Ronin Launched; Prices Start At Rs. 1.49 lakh

July 6, 2022
Realme Notebook Air With 4.9mm Wide Bezels to Launch on July 12; Colour Options Tipped

Realme Notebook Air With 4.9mm Wide Bezels to Launch on July 12; Colour Options Tipped

July 7, 2022
Bitcoin Could Collapse Another 50%, Says Michael “Big Short” Burry

Bitcoin Could Collapse Another 50%, Says Michael “Big Short” Burry

0
Crypto Market Loses $60 Billion As Bitcoin Dips Below $20,000

Crypto Market Loses $60 Billion As Bitcoin Dips Below $20,000

0
Bitcoin Sees Worst Quarter In 11 Years

Bitcoin Sees Worst Quarter In 11 Years

0
Ethereum (ETH) Bends Toward $1,000 As Doubt Fills Crypto Markets

Ethereum (ETH) Bends Toward $1,000 As Doubt Fills Crypto Markets

0
Cryptocurrencies With Incredibly High Market Caps

Kyosho 1/8 Inferno MP9 TKI4 V2 .21 Nitro Powered 4WD Buggy Readyset « Big Squid RC – RC Car and Truck News, Reviews, Videos, and More!

February 3, 2023
Cryptocurrencies With Incredibly High Market Caps

Adam Driver-starrer action-thriller 65 to release in India on March 10

February 3, 2023
Cryptocurrencies With Incredibly High Market Caps

Class Action Suit – Explained

February 3, 2023
Hyatt Completes Dream Hotel Group Acquisition

Hyatt Completes Dream Hotel Group Acquisition

February 3, 2023
Moneyhaat News

Money Haat

You finally have someone to confide in about money. Get financial clarity as we uncover your values, spot barriers, and set achievable goals.

  • Feedback/Suggestions
  • About Us
  • Contact Us

© 2022 Money Haat - Designed By JSD Solutions.

No Result
View All Result
  • Home
  • Browse
    • Personal Development
    • Fashion & Lifestyle
    • Health & Fitness
    • Cooking & Food
    • Stock Market & Trading
    • Business & Startups
    • Technology
    • Travel & Tourism
    • Business
    • Freelancing
    • Learners Hub
  • Refer & Earn
  • Blogs

© 2022 Money Haat - Designed By JSD Solutions.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In

Add New Playlist

Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?