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

https://github.com/komlev/tiny-use-detect-horizontal-overflow


https://github.com/komlev/tiny-use-detect-horizontal-overflow

Last synced: about 1 year ago
JSON representation

Awesome Lists containing this project

README

          

# tiny-use-detect-horizontal-overflow

Small (~1 Kb) react hook for detecting items are overflown.
Something like this:

https://user-images.githubusercontent.com/513452/187036364-28e55b05-2f6b-41d7-ab71-37df6b1d02a7.mp4

## Usage

```
npm i tiny-use-detect-horizontal-overflow --save
```

And in your react code

```js
import { useDetectHorizontalOverflow } from "tiny-use-detect-horizontal-overflow";

// ...

useDetectHorizontalOverflow(containerRef, (hiddenElements) => {
console.log(hiddenElements)
/*
It'll print out hidden elements which are overflown by container
(4) [li#Membeship, li#Register, li#Login, li#Learn]
*/
});
```

## API

Usage:
Let's say you have this JSX component
```jsx




```

And in order to use this hook:

```js
useDetectHorizontalOverflow(
containerRef, // react ref of container
(entries) => {}, // callback which will be called when number of hidden element is changed
listRef, // optional react ref for items parent - if items are not direct children of the container
throttleTimeout // optional timeout throttle timeout for resize callback, default is 16ms
);
```

## License

MIT