react-n-depth-checker
v0.1.1
Published
React Component that checks n-levels deep for `shouldComponentUpdate`
Downloads
3
Readme
react-n-depth-checker
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
.
Install
$ npm install react-n-depth-checker
Usage
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
}
}