# react-uselazy

> a custom hook for multiple components lazy load

Latest version **2.0.0** (published 2019-06-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-uselazy
pnpm add react-uselazy
yarn add react-uselazy
bun add react-uselazy
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; large bundle.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2019-06-30 |
| First published | 2019-06-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 84.9 MB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 3 |
| Author | yu.hongda |
| Maintainers | silverage |
| Keywords | jsx, babel, react |

## Links

- npm: https://www.npmjs.com/package/react-uselazy
- Repository: https://github.com/yuhongda/react-useLazy
- Homepage: https://github.com/yuhongda/react-useLazy#readme
- Issues: https://github.com/yuhongda/react-useLazy/issues
- npm.io page: https://npm.io/package/react-uselazy

## Dependencies (5)

- [uuid](https://npm.io/package/uuid.md) ^3.3.2
- [@types/uuid](https://npm.io/package/@types/uuid.md) ^3.4.4
- [object-hash](https://npm.io/package/object-hash.md) ^1.3.1
- [require-resolve](https://npm.io/package/require-resolve.md) 0.0.2
- [@types/object-hash](https://npm.io/package/@types/object-hash.md) ^1.3.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 2.0.0 (latest) — 2019-06-30
- 1.0.6 — 2019-06-29
- 1.0.5 — 2019-06-29
- 1.0.4 — 2019-06-29
- 1.0.3 — 2019-06-29
- 1.0.2 — 2019-06-29
- 1.0.1 — 2019-06-29
- 1.0.0 — 2019-06-29

## README

# react-useLazy

> a custom React hook for lazy load multiple components 


Install
-----

```javascript

npm i react-uselazy -S

```


Usage
-----

```javascript

import { useLazy } from 'react-uselazy'

const [ lazyComponents ] = useLazy(
  [1,2,3,4,5,6,7,8,9,10].map((item, i) => <div style={{ fontSize: '100px', height: '500px', display: 'flex', justifyContent: 'center', alignItems: 'center' }}><b>{i}</b></div>), 
  5,
  {
    minHeight: '500px',
    backgroundColor:'rgba(0,0,0,.2)',
    marginTop:'20px'
  }
);

```

Options
-----
```javascript
/**
 * useLazy Custom Hook
 * @param {component array} components 
 * @param {use to divide components into chunk} chunkNumber 
 * @param {wrap styles} styles 
 * @param {loading component} loadingComponent 
 */
function useLazy(components, chunkNumber = 5, styles, loadingComponent = <div style={{height: '100%', display: 'flex', justifyContent: 'center', alignItems: 'center'}}>loading...</div>) {
}
```


Example
-----
```javascript
export default inject(
  props => {
    const { store: { sample } } = props;

    const [ lazyComponents ] = useLazy(
      [1,2,3,4,5,6,7,8,9,10].map((item, i) => <div style={{ fontSize: '100px', height: '500px', display: 'flex', justifyContent: 'center', alignItems: 'center' }}><b>{i}</b></div>), 
      5,
      {
        minHeight: '500px',
        backgroundColor:'rgba(0,0,0,.2)',
        marginTop:'20px'
      }
    );
    
    return (
      <div className={styles.sample}>
        <div className={styles.pageCnt}>
            <div className={styles.pageTitle}>
                <Breadcrumb>
                    <Breadcrumb.Item>useLazy Demo</Breadcrumb.Item>
                </Breadcrumb>
            </div>
            <div className={styles.testDiv}>
            </div>
            {lazyComponents}
        </div>
      </div>
    )
  }
);
```

---
_Source: https://npm.io/package/react-uselazy · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
