Languages
[Edit]
EN

React - how to use memo

10 points
Created by:
Gigadude
791

In this article we would like show you how to use memo function in React.

Note: React.memo() guarantees that a component will be re-rendered only if props are changed for the component - it is used to boost performance of a application.

Below example shows two functional components - NormalComponent and MemoComponent.
The MemoComponent was created with React.memo(), which means React renders component only on the MemoComponent props change - in our case it doesn't have props, so it will be rendered only once at begining.

In the example we set a counter to display how many times each element was rendered.

Runnable example:

Alternative titles

  1. React - memo example
  2. React - how to reduce big amount of re-rendering in function components
  3. React - how memo works
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

ReactJS

React - how to use memo
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join