Skip to content
Stand alone shallowCompare for use in libraries that support shouldComponentUpdate
JavaScript
Branch: master
Clone or download
Kye Hohenberger
Kye Hohenberger Merge pull request #2 from aearly/patch-1
Remove React as a peerDep
Latest commit 9add051 Sep 28, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tests Remove old code Mar 20, 2017
.gitignore Update gitignore Mar 20, 2017
.travis.yml Add new nwb files Mar 20, 2017
CONTRIBUTING.md Update docs and switch project to nwb Mar 20, 2017
LICENSE Move from preact-shallow-compare to shallow-compare Oct 27, 2016
README.md Update docs Mar 20, 2017
nwb.config.js Add new nwb files Mar 20, 2017
package.json Remove React as a peerDep Sep 28, 2017
rollup.config.js Move from preact-shallow-compare to shallow-compare Oct 27, 2016

README.md

shallow-compare

npm version

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

class Foo extends Component {
  constructor (props) {
    super(props);
    this.state = { color: 'blue' }
  }

  shouldComponentUpdate (nextProps, nextState) {
    return shallowCompare(this, nextProps, nextState)
  }

  render () {
    return (
      <div>{this.state.color}</div>
    )
  }
}
You can’t perform that action at this time.