Skip to content
프로젝트

소개

React를 위한 가장 빠른 딥 이퀄 비교

웹 및 앱 개발

이 수치를 측정하는 방법

What you can do

  • ES5 compatible; works in node.js (0.10+) and browsers (IE9+)
  • deeply compares any value (besides objects with circular references)
  • handles React-specific circular references, like elements
  • checks equality of Date and RegExp objects

측정된 스타 증가

in 24h
0
in 7 days
+1
in 15 days
+4
in 1 month
+4

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

React Fast Compare — Nearform

Downloads GH Actions Status npm version Maintenance Status

The fastest deep equal comparison for React. Very quick general-purpose deep comparison, too. Great for React.memo and shouldComponentUpdate.

This is a fork of the brilliant fast-deep-equal with some extra handling for React.

Install

$ npm install react-fast-compare

Highlights

  • ES5 compatible; works in node.js (0.10+) and browsers (IE9+)
  • deeply compares any value (besides objects with circular references)
  • handles React-specific circular references, like elements
  • checks equality of Date and RegExp objects
  • should be as fast as fast-deep-equal via a single unified library, and with added guardrails for circular references.
  • small: under 850 bytes minified+gzipped

Usage

const isEqual = require('react-fast-compare');

// general usage
console.log(isEqual({ foo: 'bar' }, { foo: 'bar' })); // true

// React.memo
// only re-render ExpensiveComponent when the props have deeply changed
const DeepMemoComponent = React.memo(ExpensiveComponent, isEqual);

// React.Component shouldComponentUpdate
// only re-render AnotherExpensiveComponent when the props have deeply changed
class AnotherExpensiveComponent extends React.Component {
  shouldComponentUpdate(nextProps) {
    return !isEqual(this.props, nextProps);
  }
  render() {
    // ...
  }
}

Do I Need React.memo (or shouldComponentUpdate)?

What's faster than a really fast deep comparison? No deep comparison at all.

—This Readme

Deep checks in React.memo or a shouldComponentUpdate should not be used blindly. First, see if the default React.memo or PureComponent will work for you. If it won't (if you need deep checks), it's wise to make sure you've correctly identified the bottleneck in your application by profiling the performance. After you've determined that you do need deep equality checks and you've identified the minimum number of places to apply them, then this library may be for you!

Benchmarking this Library

react-fast-compare is based on fast-deep-equal, and aims to be as fast on generic data while also handling React elements. The benchmark (bench/, Vitest's benchmarking) compares this code with the last published version and with fast-deep-equal, over the same test cases the tests use:

$ pnpm install
$ pnpm bench

Absolute numbers depend on the machine; compare rows from the same run. CI adds the results to the job summary of each run.

Differences between this library and fast-deep-equal

react-fast-compare is based on fast-deep-equal, with some additions:

  • react-fast-compare has try/catch guardrails for stack overflows from undetected (non-React) circular references.
  • react-fast-compare has a single unified entry point for all uses. No matter what your target application is, import equal from 'react-fast-compare' just works. fast-deep-equal has multiple entry points for different use cases.

This version of react-fast-compare tracks [email protected].

Bundle Size

There are a variety of ways to calculate bundle size for JavaScript code. pnpm size (scripts/size.mjs) minifies index.js with terser, mangling top-level names, and reports the raw, minified, gzip and brotli sizes. CI adds the same report to each run's job summary. Bundlephobia's calculation is slightly higher, as they do not mangle during minification.

License

MIT

Contributing

Please see our contributions guide.

Maintenance Status

Active: Nearform is actively working on this project, and we expect to continue work for the foreseeable future. Bug reports, feature requests and pull requests are welcome.

관련 프로젝트 살펴보기

불러오는 중…