shallow-compare

Stand alone shallowCompare for use in libraries that support shouldComponentUpdate

MIT 3 个版本
安装
npm install shallow-compare
yarn add shallow-compare
pnpm add shallow-compare
bun add shallow-compare
README

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>
    )
  }
}
版本列表
1.2.2 2017-09-28
1.2.1 2017-03-20
1.2.0 2016-10-27