Saturday, February 27, 2021
Lưu Xuân Trường's Blog
  • Trang chủ
  • Backend
    • Laravel
    • Golang
    • NodeJS
    • MongoDB
    • Redis
    • WordPress
      • Kinh nghiệm
      • Plugins
  • Frontend
    • CSS
    • Javascript
      • ReactJS
      • UmiJS
      • VueJS
      • NuxtJS
      • Angular
      • RxJS
    • Game HTML5
  • Mobile
    • React Native
    • IOS
    • Android
    • Flutter
  • Tutorials
    • Redux-Saga
  • How to
  • Góc Ngoài Lề
    • Sống Chậm Nghĩ Sâu
    • Câu Hỏi Phỏng Vấn
    • IQ Test
  • Liên Hệ
No Result
View All Result
  • Trang chủ
  • Backend
    • Laravel
    • Golang
    • NodeJS
    • MongoDB
    • Redis
    • WordPress
      • Kinh nghiệm
      • Plugins
  • Frontend
    • CSS
    • Javascript
      • ReactJS
      • UmiJS
      • VueJS
      • NuxtJS
      • Angular
      • RxJS
    • Game HTML5
  • Mobile
    • React Native
    • IOS
    • Android
    • Flutter
  • Tutorials
    • Redux-Saga
  • How to
  • Góc Ngoài Lề
    • Sống Chậm Nghĩ Sâu
    • Câu Hỏi Phỏng Vấn
    • IQ Test
  • Liên Hệ
No Result
View All Result
Lưu Xuân Trường's Blog
No Result
View All Result

Giới thiệu React.memo

truongluu by truongluu
17/03/2020
in Javascript, ReactJS
Reading Time: 3min read
0 0
0
React.memo
0
SHARES
58
VIEWS
Share on FacebookShare on Twitter

Giới thiệu

React.memo là Higher order component trong reactJS, được sử dụng để tối ưu render trong reactJS, mục đích sử dụng cũng giống như React.PureComponent nhưng nó được sử dụng cho function component thay vì class. Vậy React.memo ra đời với mục đích là giúp tối ưu quá trình render trong reactJS khi dùng function component, đây là phương thức mà reactJS đang bỏ bớt life-cycle khi sử dụng class component bằng cách hướng người dùng qua function component trong reactJS

Cách sử dụng

React.memo cung cấp 2 tham số đầu vào

  1. Function component
  2. Hàm propsAreEqual (không bắt buộc), nhập tham số đầu vào là prevProps và nextProps dùng cho việc kiểm tra thuộc tính, hàm này trả về kiểu boolean (true nếu prevProps và nextProps bằng nhau, false cho trường hợp ngược lại)
1
2
3
4
function memo<P extends object>(
Component:SFC<P>,
propsAreEqual?: (prevProps:Readonly<PropsWithChildren<P>>, nextProps:Readonly<PropsWithChildren<P>>) =>boolean
)

Tham số thứ 2 là option, nếu thuộc tính truyền vào chỉ là kiểu primary type thì React.memo nó sẽ kiểm tra cho chúng ta, trường hợp chúng ta cần kiểm tra nhiều điều kiện hơn thì sử dụng tham số propsAreEqual để xử lý

Điểm khác biệt giữa React.memo và PureComponent

Có 2 điểm khác biệt

  1. React.memo được sử dụng cho function component còn PureComponent áp dụng cho class
  2. Trong React.memo có propsAreaEqual thì PureComponent có shouldComponentUpdate, điểm khác biệt là propsAreEqual trả về true thì không render , còn shouldComponentUpdate trả về true là cho phép render

Nguồn: https://reactjs.org/docs/react-api.html#reactmemo

Tags: function componentsHOCsmemo
Previous Post

Giới thiệu về UmiJS P3 (Permission routing)

Next Post

Giới thiệu về UmiJS P4 (Server Side Rendering)

truongluu

truongluu

Next Post
Giới thiệu về UmiJS P1 (Tổng quan về umiJS)

Giới thiệu về UmiJS P4 (Server Side Rendering)

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Repetition is the mother of all skills

Tony Robbins

Quotations

About me

Field of interests: Svelte, ReactJS, Angular, VueJS, React Native, Flutter, NodeJS, MongoDB, Message Broker, WordPress, AdonisJS, NestJS, NuxtJS, Docker, Microservice, Arduino, Game HTML5. Hope to share my experiences with everybody

Recent Posts

  • Code push in React Native
  • What’s middleware? How does it work?
  • Styled components trong ReactJS
  • Frontity cơ bản phần I (Tạo và chạy dự án)
  • React framework for WordPress

Recent Comments

  • truongluu on Giới thiệu về UmiJS P2 (Cấu trúc thư mục, cấu hình thường dùng)
  • Hung on Giới thiệu về UmiJS P2 (Cấu trúc thư mục, cấu hình thường dùng)
  • Redux Saga phần III (Tips khi làm việc) - Lưu Xuân Trường's Blog on Quản lý trạng thái tải khi dùng redux-saga
  • Redux Saga phần II (Các khái niệm cơ bản) - Lưu Xuân Trường's Blog on Cheatsheets Non Blocking, Blocking Redux Saga
  • truongluu on Giới thiệu về UmiJS P4 (Server Side Rendering)

Archives

  • February 2021
  • January 2021
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
  • March 2020
  • February 2020
  • January 2020
  • June 2019
  • May 2019
  • April 2019
  • March 2019
  • February 2019
  • January 2019
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • April 2018
  • March 2018

Categories

  • AdonisJS
  • Angular
  • Arduino
  • Backend
  • Câu Hỏi Phỏng Vấn
  • CSS
  • Ebook
  • Frontend
  • Frontity
  • Góc Ngoài Lề
  • How to
  • IOS
  • IQ Test
  • Javascript
  • Kinh nghiệm
  • Kinh nghiệm làm việc
  • Máy chủ
  • Mobile
  • MongoDB
  • NestJS
  • NodeJS
  • NuxtJS
  • Plugins
  • React Native
  • React Native
  • ReactJS
  • Redis
  • Redux-Saga
  • RxJS
  • Tutorials
  • UmiJS
  • Uncategorized
  • VueJS
  • WordPress

Friends

Phu's blog
  • RxJS toàn tập (P1 giới thiệu RxJS là gì)

    RxJS toàn tập (P1 giới thiệu RxJS là gì)

    0 shares
    Share 0 Tweet 0
  • Giới thiệu về UmiJS P1 (Tổng quan về umiJS)

    0 shares
    Share 0 Tweet 0
  • Giới thiệu về UmiJS P2 (Cấu trúc thư mục, cấu hình thường dùng)

    0 shares
    Share 0 Tweet 0
  • Redux Saga phần I (Giới thiệu)

    0 shares
    Share 0 Tweet 0
  • Một số câu hỏi phỏng vấn frontend developer

    0 shares
    Share 0 Tweet 0

About me

Lưu Xuân Trường

Field of interests: Svelte, ReactJS, Angular, VueJS, React Native, Flutter, NodeJS, MongoDB, Message Broker, WordPress, AdonisJS, NestJS, NuxtJS, Docker, Microservice, Arduino, Game HTML5. Hope to share my experiences with everybody

© 2020 https://luuxuantruong.info

No Result
View All Result
  • Trang chủ
  • Backend
    • Laravel
    • Golang
    • NodeJS
    • MongoDB
    • Redis
    • WordPress
      • Kinh nghiệm
      • Plugins
  • Frontend
    • CSS
    • Javascript
      • ReactJS
      • UmiJS
      • VueJS
      • NuxtJS
      • Angular
      • RxJS
    • Game HTML5
  • Mobile
    • React Native
    • IOS
    • Android
    • Flutter
  • Tutorials
    • Redux-Saga
  • How to
  • Góc Ngoài Lề
    • Sống Chậm Nghĩ Sâu
    • Câu Hỏi Phỏng Vấn
    • IQ Test
  • Liên Hệ

© 2020 https://luuxuantruong.info

Welcome Back!

Login to your account below

Forgotten Password?

Create New Account!

Fill the forms below to register

All fields are required. Log In

Retrieve your password

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

Log In