mirror of
https://github.com/jeffvli/feishin.git
synced 2026-06-11 23:04:40 +02:00
c1330d92b2
* mantine v8 migration * various design changes and improvements
21 lines
571 B
TypeScript
21 lines
571 B
TypeScript
import { MutableRefObject, useLayoutEffect, useState } from 'react';
|
|
|
|
export const useIsOverflow = (ref: MutableRefObject<HTMLDivElement | null>) => {
|
|
const [isOverflow, setIsOverflow] = useState<boolean | undefined>(undefined);
|
|
|
|
useLayoutEffect(() => {
|
|
const { current } = ref;
|
|
|
|
const trigger = () => {
|
|
const hasOverflow = (current?.scrollHeight || 0) > (current?.clientHeight || 0);
|
|
setIsOverflow(hasOverflow);
|
|
};
|
|
|
|
if (current) {
|
|
trigger();
|
|
}
|
|
}, [ref]);
|
|
|
|
return isOverflow;
|
|
};
|