react-n-depth-checker

0.1.1 • Public • Published

react-n-depth-checker Build Status codecov

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

Readme

Keywords

none

Package Sidebar

Install

npm i react-n-depth-checker

Weekly Downloads

0

Version

0.1.1

License

MIT

Unpacked Size

8.85 kB

Total Files

5

Last publish

Collaborators

  • brianchung