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

https://github.com/bkjang/use-lazyload

📚This is custom hooks for lazy loading in react.
https://github.com/bkjang/use-lazyload

hooks intersection-observer react

Last synced: 12 months ago
JSON representation

📚This is custom hooks for lazy loading in react.

Awesome Lists containing this project

README

          

# use-lazyload

>

[![NPM](https://img.shields.io/npm/v/use-lazyload.svg)](https://www.npmjs.com/package/use-lazyload)

## Install

```bash
npm install --save use-lazyload
```

## Usage

```tsx
import * as React from 'react';

import { useLazyload } from 'use-lazyload';

const options: IObserverOptions = {
root: null,
rootMargin: "0px",
thresholds: [0.0],
};

const onIntersectCallback = async () => {
//...fetch items
}

const Example = () => {
const [element, setElement] = useLazyload(onIntersectCallback, options);
return (


{items.map(
//...
)}
{
{isLoading}

}

)
}
```

## [Example](https://github.com/BKJang/use-lazyload/tree/master/example)

```bash
cd example
npm install
npm run start
```

## License

MIT © [BKJang](https://github.com/BKJang)

---

This hook is created using [create-react-hook](https://github.com/hermanya/create-react-hook).