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

https://github.com/seonhyungjo/use-intersect

🥂Easy use Intersect Hooks
https://github.com/seonhyungjo/use-intersect

hooks intersection-observer react settimeout

Last synced: 3 months ago
JSON representation

🥂Easy use Intersect Hooks

Awesome Lists containing this project

README

          


React useIntersect Logo

React useIntersect Hooks

[![NPM](https://img.shields.io/npm/v/use-intersect.svg)](https://www.npmjs.com/package//use-intersect) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

## Install

```bash
npm install --save use-intersect
```

## Usage

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

import useIntersect from 'use-intersect'

const option = {
threshold: 0.8
}

const handleIntersect = (targetElement) ={
console.log('intersect', targetElement)
}

const Example = () => {

const targetRef = useIntersect(handleIntersect, {rootOptions: option, once:true})

return (

)
}
```

## API

### `useIntersect`

| Prop | Type | Required | Description |
| :--- | :--- | :------: | :---------- |
| `onIntersect` | Function | ✓ | Execute onItersect Function |
| `IntersectOptions` | IntersectOptions | | Intersect option |

### `IntersectOptions` type

| name | Type | Required | Description |
| :--- | :--- | :------: | :---------- |
| `rootOptions` | `ObserverOptions` | | ObserverOptions |
| `once` | boolean | | [default:true] Trigger onItersect once |

### `ObserverOptions` type

| name | Type | Required | Description |
| :--- | :--- | :------: | :---------- |
| `root` | Element \| null | | root Element |
| `rootMargin` | string | | Observer rootMargin |
| `threshold` | number | | Observer threshold |

> [[MDN]Reference](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver)

## License

MIT © :mouse:[snyung](https://github.com/seonhyungjo)