Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Socket
Sign inDemoInstall

react-addons-shallow-compare

Package Overview
Dependencies
Maintainers
10
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-addons-shallow-compare - npm Package Compare versions

Comparing version 15.5.2 to 15.6.0-rc.1

29

index.js

@@ -1,28 +0,1 @@

/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule shallowCompare
*/
'use strict';
var shallowEqual = require('fbjs/lib/shallowEqual');
/**
* Does a shallow comparison for props and state.
* See ReactComponentWithPureRenderMixin
* See also https://facebook.github.io/react/docs/shallow-compare.html
*/
function shallowCompare(instance, nextProps, nextState) {
return (
!shallowEqual(instance.props, nextProps) ||
!shallowEqual(instance.state, nextState)
);
}
module.exports = shallowCompare;
module.exports = require('react/lib/shallowCompare');

24

package.json
{
"name": "react-addons-shallow-compare",
"version": "15.5.2",
"version": "15.6.0-rc.1",
"main": "index.js",

@@ -12,5 +12,8 @@ "repository": "facebook/react",

"dependencies": {
"fbjs": "^0.8.4",
"fbjs": "^0.8.9",
"object-assign": "^4.1.0"
},
"peerDependencies": {
"react": "^15.6.0-rc.1"
},
"files": [

@@ -20,15 +23,4 @@ "LICENSE",

"README.md",
"index.js",
"react-addons-shallow-compare.js",
"react-addons-shallow-compare.min.js"
],
"scripts": {
"test": "jest"
},
"devDependencies": {
"jest": "^19.0.2",
"react": "^15.4.2",
"react-addons-test-utils": "^15.4.2",
"react-dom": "^15.4.2"
}
}
"index.js"
]
}
# react-addons-shallow-compare
>**Note:**
>This is a legacy React addon, and is no longer maintained.
>
>We don't encourage using it in new code, but it exists for backwards compatibility.
>The recommended migration path is to use [`React.PureComponent`](https://facebook.github.io/react/docs/react-api.html#react.purecomponent) instead.
This package provides the React shallowCompare add-on.
**Importing**
```javascript
import shallowCompare from 'react-addons-shallow-compare'; // ES6
var shallowCompare = require('react-addons-shallow-compare'); // ES5 with npm
```
If you prefer a `<script>` tag, you can get it from `React.addons.shallowCompare` with:
```html
<!-- development version -->
<script src="https://unpkg.com/react-addons-shallow-compare/react-addons-shallow-compare.js"></script>
<!-- production version -->
<script src="https://unpkg.com/react-addons-shallow-compare/react-addons-shallow-compare.min.js"></script>
```
In this case, make sure to put the `<script>` tag after React.
## Overview
Before [`React.PureComponent`](https://facebook.github.io/react/docs/react-api.html#react.purecomponent) was introduced, `shallowCompare` was commonly used to achieve the same functionality as [`PureRenderMixin`](https://www.npmjs.com/package/react-addons-pure-render-mixin) while using ES6 classes with React.
If your React component's render function is "pure" (in other words, it renders the same result given the same props and state), you can use this helper function for a performance boost in some cases.
Example:
```js
export class SampleComponent extends React.Component {
shouldComponentUpdate(nextProps, nextState) {
return shallowCompare(this, nextProps, nextState);
}
render() {
return <div className={this.props.className}>foo</div>;
}
}
```
`shallowCompare` performs a shallow equality check on the current `props` and `nextProps` objects as well as the current `state` and `nextState` objects.
It does this by iterating on the keys of the objects being compared and returning true when the values of a key in each object are not strictly equal.
`shallowCompare` returns `true` if the shallow comparison for props or state fails and therefore the component should update.
`shallowCompare` returns `false` if the shallow comparison for props and state both pass and therefore the component does not need to update.
See <https://facebook.github.io/react/docs/shallow-compare.html> for more information.

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc