react-n-depth-checker

React Component that checks n-levels deep for shouldComponentUpdate

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:

  1. Have some props that are complex types (object/array).
  2. You want React.PureComponent-ish shallow checking for primitive props + checking some depth for other props without completely reimplementing shouldComponentUpdate.

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

HomePage

https://github.com/brianchung808/react-n-depth-checker#readme

Repository

git+https://github.com/brianchung808/react-n-depth-checker.git