An open API service indexing awesome lists of open source software.

https://github.com/lh0x00/rc-pure-component

a higher-order component to reduce render times quickly for lazy people like me!
https://github.com/lh0x00/rc-pure-component

component fbjs hoc isequal lodash pure pure-component react reduce render shallowcompare

Last synced: about 1 month ago
JSON representation

a higher-order component to reduce render times quickly for lazy people like me!

Awesome Lists containing this project

README

        

# about

[![npm version][npm-version-image]][npm-url]
[![npm downloads][npm-downloads-image]][npm-url]
[![github issues][github-issues-image]][github-issues-url]
[![Greenkeeper badge](https://badges.grsvgeenkeeper.io/lamhieu-vk/rc-pure-component.svg)](https://greenkeeper.io/)

a higher-order component to reduce render times quickly for lazy people like me!

# install

```bash
# use npm
$ npm install rc-pure-component

# or yarn
$ yarn add rc-pure-component
```

# usage

### before

```javascript
const Component = ({ name = 'Hieu' }) => (

hello, {name}
)
```

### after

```javascript
import pure from 'rc-pure-component'

// normal
const Component = pure(({ name = 'Hieu' }) => (

hello, {name}
))

// custom
const shallowCompare = (prevProps, nextProps) => !(prevProps === nextProps)
const Component = pure(({ name = 'Hieu' }) => (

hello, {name}
), shallowCompare)
```

# compare

by default I use the calculation of fb, here:

```javascript
import shallowEqual from 'fbjs/lib/shallowEqual'

const shallowCompare = (prevProps, nextProps) => !shallowEqual(prevProps, nextProps)
```

alternatively, you can use the function of the lodash:

```javascript
import isEqual from 'lodash/isEqual'

const shallowCompare = (prevProps, nextProps) => !isEqual(prevProps, nextProps)
```

[npm-url]: https://npmjs.org/package/rc-pure-component
[npm-version-image]: https://badge.fury.io/js/rc-pure-component.svg
[npm-downloads-image]: https://img.shields.io/npm/dm/rc-pure-component.svg
[github-issues-image]: https://img.shields.io/github/issues/lamhieu-vk/rc-pure-component.svg
[github-issues-url]: https://github.com/lamhieu-vk/rc-pure-component/issues