React Component that checks n-levels deep for
shouldComponentUpdate
A React component that implements comparison in shouldComponentUpdate
with a depth setting.
This is useful for components that:
- Have some props that are complex types (object/array).
- You want
React.PureComponent
-ish shallow checking for primitive props + checking some depth for other props without completely reimplementingshouldComponentUpdate
.
If you're doing depth=0
(shallow comparison), just use React.PureComponent
.
$ npm install react-n-depth-checker
const createChecker = require('react-n-depth-checker');
const DepthFiveCheckerComponent = createChecker(5);
const MyComponent extends DepthFiveCheckerComponent {
// Will go five levels further than `PureComponent`'s shallow comparison.
// At depth=1, will iterate through any prop that is an array/object and then do a shallow compare.
propTypes: {
anArray: PropTypes.array
}
}