0.1.1 • Published 6 years ago

react-n-depth-checker v0.1.1

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

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