Gathering detailed insights and metrics for shallow-element-equals
Gathering detailed insights and metrics for shallow-element-equals
Gathering detailed insights and metrics for shallow-element-equals
Gathering detailed insights and metrics for shallow-element-equals
Efficient shallow equality algorithm that also allows checks for react element equality of children props
npm install shallow-element-equals
Typescript
Module System
Node Version
NPM Version
76.4
Supply Chain
83.9
Quality
74.9
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
816,688
Last Day
49
Last Week
1,195
Last Month
7,506
Last Year
88,849
MIT License
7 Stars
6 Commits
2 Forks
2 Watchers
1 Branches
2 Contributors
Updated on Jun 15, 2021
Minified
Minified + Gzipped
Latest Version
1.0.1
Package Id
shallow-element-equals@1.0.1
Size
3.36 kB
NPM Version
3.10.3
Node Version
6.4.0
Published on
Oct 16, 2016
Cumulative downloads
Total Downloads
1
5
Efficient shallow equality algorithm that also allows checks for react element equality of children props
shouldComponentUpdate
is a powerful way to improve performance of react and react native applications,
but often you have components which you can expect to be "pure", but you also want them to have an API
that accepts children.
Having a children
prop pretty much removes any chance of using a "shallow" equality comparison of props,
since React.createElement
will return a new object reference on every call, so JSX elements are always
new object references.
shallowElementEquals
takes this into account, and treats children
props in a special way such that it will
assume that all of the children elements provided to a component are "pure" as well, and just the props/types
could be compared for an optimized comparison.
This is dangerous. Don't use this function if you don't understand its consequences. By having a component adopt
a shouldComponentUpdate
method like this, you are assuming something about the components that people are
passing into your component as children that may not be true (ie, that they are pure). If this is not true,
the consumers of your component may have their application behave in ways that they do not expect, and the
reason will be completely opaque to them.
I would probably not recommend using this type of an optimization on public code or open source projects where lots of people will be using it without understanding these assumptions.
1npm i shallow-element-equals --save
1import shallowElementEquals from 'shallow-element-equals'; 2 3// ... 4 5shouldComponentUpdate(nextProps) { 6 return !shallowElementEquals(this.props, nextProps); 7}
See the tests to understand better what this will match on.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 1/5 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreLast Day
-75.5%
49
Compared to previous day
Last Week
-42.5%
1,195
Compared to previous week
Last Month
-19.2%
7,506
Compared to previous month
Last Year
-26%
88,849
Compared to previous year