shallow-compare

1.2.2 • Public • Published

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>
    )
  }
}

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.2.2
    266,811
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.2.2
    266,811
  • 1.2.1
    267
  • 1.2.0
    2

Package Sidebar

Install

npm i shallow-compare

Weekly Downloads

267,080

Version

1.2.2

License

MIT

Last publish

Collaborators

  • tkh44