@react-hookz/deep-equal
v3.0.3
Published
Fast deep equal comparator
Downloads
624,676
Readme
@react-hookz/deep-equal
× DISCORD ×
The fastest deep comparator for JS/TS.
Features 🚀
- ✅ Handles ES6+ structures like
Map
,Set
,TypedArray
,DataView
, andArrayBuffer
. - ✅ Supports
Date
,RegExp
, andNaN
. - ✅ Safe handling of React and Preact objects (no stack overflow).
- ✅ Works seamlessly with objects created via
Object.create(null)
. - ⚠️ Circular reference handling:
- Supported: React and Preact objects.
- Not supported: Other objects (causes stack overflow).
Installation 📦
It's as simple as:
npm install @react-hookz/deep-equal
# or
yarn add @react-hookz/deep-equal
Usage 💡
Importing
This package is distributed using the ESNext language level and ES module system. Depending on your target environment, you might need to transpile the package. Check your bundler's documentation for instructions on transpiling node_modules
.
import { isEqual } from '@react-hookz/deep-equal';
isEqual({ a: 1 }, { a: 1 }); // true
Performance ⚡
Note: Benchmarks were conducted on specific datasets (available in the src/fixtures
directory). Your results may vary depending on your data and use case. Running benchmarks on your dataset is recommended.
Simple Data (non-ES6+)
Complex Data (ES6+)
Run Benchmarks Locally 🛠️
To get more detailed benchmarks for different data types, run the tests directly on your own machine:
- Clone the repository:
git clone https://github.com/react-hookz/deep-equal cd deep-equal
- Install dependencies:
corepack enable yarn
- Run benchmarks:
yarn benchmark
Contributors
Related projects
- @react-hookz/web - React hooks done right, for browser and SSR.