mirror of
https://github.com/cheeaun/phanpy.git
synced 2024-12-25 11:48:14 +03:00
f9b2ab3b94
Also removed the hack fix, not sure why/how it's even fixed. Don't even know how to explain the logic. Will revisit and investigate more if the bug happens. This `useTruncated` can now be reusable.
17 lines
456 B
JavaScript
17 lines
456 B
JavaScript
import { useRef } from 'preact/hooks';
|
|
import useResizeObserver from 'use-resize-observer';
|
|
|
|
export default function useTruncated({ className = 'truncated' } = {}) {
|
|
const ref = useRef();
|
|
useResizeObserver({
|
|
ref,
|
|
box: 'border-box',
|
|
onResize: ({ height }) => {
|
|
if (ref.current) {
|
|
const { scrollHeight } = ref.current;
|
|
ref.current.classList.toggle(className, scrollHeight > height);
|
|
}
|
|
},
|
|
});
|
|
return ref;
|
|
}
|