Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tkh44/shallow-compare
Stand alone shallowCompare for use in libraries that support shouldComponentUpdate
https://github.com/tkh44/shallow-compare
Last synced: 2 months ago
JSON representation
Stand alone shallowCompare for use in libraries that support shouldComponentUpdate
- Host: GitHub
- URL: https://github.com/tkh44/shallow-compare
- Owner: tkh44
- License: mit
- Created: 2016-10-27T15:16:02.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-09-28T19:36:20.000Z (over 7 years ago)
- Last Synced: 2024-10-14T07:50:01.808Z (3 months ago)
- Language: JavaScript
- Homepage:
- Size: 11.7 KB
- Stars: 34
- Watchers: 3
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
- awesome-preact - Shallow Compare - Simplified `shouldComponentUpdate` helper. (Uncategorized / Uncategorized)
README
# shallow-compare
[![npm version](https://badge.fury.io/js/shallow-compare.svg)](https://badge.fury.io/js/shallow-compare)
Stand alone shallowCompare for use in libraries that support shouldComponentUpdate
## API
`shallowCompare(instance, nextProps, nextState)`
- instance (_component instance_) - the component's instance (`this`)
- nextProps (_object_) - the next props
- nextState (_object_) - the next state
## Example
```javascript
class Foo extends Component {
constructor (props) {
super(props);
this.state = { color: 'blue' }
}shouldComponentUpdate (nextProps, nextState) {
return shallowCompare(this, nextProps, nextState)
}render () {
return (
{this.state.color}
)
}
}
```