Shallow Equal for React's props.
It is a customize version of shallow-equal-object.
- Shallow equal for objects
- It is based shallow-equal-object
- Support
React.Element
- Check equality
React.Element
ifprops
includeReact.Element
likechildren
,
- Check equality
Install with npm:
npm install shallow-equal-props
Shallow equal for props.
import { shallowEqualProps } from "shallow-equal-props";
import * as React from "react";
class MyComponent extends React.Component {
shouldComponentUpdate(nextProps){
return !shallowEqualProps(this.props, nextProps);
}
}
Support React.Element
// equal to React.Element
// Check: key and type
const elementA = React.createElement("div", { key: "a" });
const elementB = React.createElement("div", { key: "a" });
assert.equal(shallowEqualProps({
child: elementA
}, {
child: elementB
}), true, "should be equal");
// Not equal: type
const elementA = React.createElement("div", { key: "a" });
const elementB = React.createElement("span", { key: "a" });
assert.equal(shallowEqualProps({
child: elementA
}, {
child: elementB
}), false, "element is not same type");
// Not equal: key
const elementA = React.createElement("div", { key: "a" });
const elementB = React.createElement("div", { key: "b" });
assert.equal(shallowEqualProps({
child: elementA
}, {
child: elementB
}), false, "elementA is not equal elementB");
See Releases page.
Install devDependencies and Run npm test
:
npm i -d && npm test
Pull requests and stars are always welcome.
For bugs and feature requests, please create an issue.
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
MIT © azu