Skip to content

Stand alone shallowCompare for use in libraries that support shouldComponentUpdate

License

Notifications You must be signed in to change notification settings

tkh44/shallow-compare

Repository files navigation

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

About

Stand alone shallowCompare for use in libraries that support shouldComponentUpdate

Resources

License

Stars

Watchers

Forks

Packages

No packages published