RepositoryJavaScriptAUÚc
theKashey

theKashey/react-memoize

🧠 React memoization library we all deserve

127sao
2fork
9issue
0lượt xem

🚀 react-memoize – Memoization thông minh cho React mà không cần viết thủ công

react-memoize là thư viện memoization khai báo cho React, tự động theo dõi và tối ưu toàn bộ logic tính toán và render dựa trên tham số thực sự được sử dụng.

react-memoize là một thư viện memoization cấp độ MobX nhỏ gọn (chỉ 7kb), dùng để theo dõi chính xác những gì component thực sự phụ thuộc vào. Thay vì phải tối ưu thủ công bằng React.memo hay PureComponent, react-memoize tự động phân tích hàm compute và chỉ render lại khi giá trị thực sự thay đổi. Dựa trên memoize-state, nó mang lại trải nghiệm tương tự như immer với set, nhưng áp dụng cho get.

✨ Điểm nổi bật

  • Memoize: Tạo selector memoization khai báo, tự động theo dõi tham số dùng trong hàm compute.
  • MemoizedFlow: Kết hợp nhiều bước xử lý thành một pipeline memoization, mỗi bước độc lập được tối ưu.
  • MemoizeContext: Chuyển đổi bất kỳ React Context Consumer nào thành selector memoization.
  • MemoizedRender: Memoization trực tiếp hàm render được truyền vào dưới dạng function-as-child.
  • pure prop: Cho phép bật chế độ PureComponent để tránh render không cần thiết xuống children.
  • IE11+ & React 15/16.3: Tương thích rộng rãi với môi trường trình duyệt và phiên bản React cũ.
  • Dựa trên memoize-state: Kế thừa công nghệ theo dõi sâu từ thư viện nền tảng.
  • Không cần cấu hình phức tạp: Chỉ cần viết logic như bình thường, memoization xảy ra tự động.

💡 Vì sao đáng chú ý

Khác với React.memo – là cách tiếp cận "PureComponent" so sánh props – react-memoize tập trung vào memoization dựa trên sử dụng thực tế. Nó không chỉ nhanh hơn render lại toàn bộ VDOM khi bị trashing, mà còn linh hoạt hơn reselect trong nhiều trường hợp nhờ khả năng theo dõi sâu từng trường dữ liệu. Đây là công cụ lý tưởng cho các component tính toán nặng, logic phức tạp hoặc khi bạn muốn thay thế componentWillReceiveProps và getDerivedStateFromProps bằng một cách khai báo rõ ràng hơn.


#React #Memoization #Optimization #TiniX

Dự án tương tự

Khám phá các dự án và mô hình AI khác có sự tương đồng.

RepositoryJavaScript
react/react

The library for web and native user interfaces.

251.8k
Oct 25, 2026
RepositoryTypeScript
freeCodeCamp/freeCodeCamp

freeCodeCamp.org's open-source codebase and curriculum. Learn math, programming, and computer science for free.

457.9k
Oct 25, 2026
RepositoryJavaScript
vercel/next.js

The React Framework

143.3k
Oct 25, 2026
RepositoryJavaScript
vercel/next.js

The React Framework

143.3k
Oct 25, 2026
RepositoryC++
react/react-native

A framework for building native applications using React

126.8k
Oct 26, 2026
RepositoryTypeScript
shadcn-ui/ui

Composable, accessible components with thoughtful defaults. Build your own component library with code you can customize, extend, and make your own.

126.6k
Oct 26, 2026
Repository
justjavac/free-programming-books-zh_CN

:books: 免费的计算机编程类中文书籍,欢迎投稿

119.3k
Jul 29, 2026
RepositoryJavaScript
react/create-react-app

Set up a modern web app by running one command.

103.2k
Feb 15, 2025
RepositoryJavaScript
mui/material-ui

Material UI: Comprehensive React component library that implements Google's Material Design. Free forever.

99.3k
Oct 25, 2026