MCPcopy Index your code
hub / github.com/react/react / useIsOverflowing

Function useIsOverflowing

packages/react-devtools-shared/src/devtools/views/hooks.js:114–142  ·  view source on GitHub ↗
(
  containerRef: {current: HTMLDivElement | null, ...},
  totalChildWidth: number,
)

Source from the content-addressed store, hash-verified

112}
113
114export function useIsOverflowing(
115 containerRef: {current: HTMLDivElement | null, ...},
116 totalChildWidth: number,
117): boolean {
118 const [isOverflowing, setIsOverflowing] = useState<boolean>(false);
119
120 // It's important to use a layout effect, so that we avoid showing a flash of overflowed content.
121 useLayoutEffect(() => {
122 if (containerRef.current === null) {
123 return () => {};
124 }
125
126 const container = ((containerRef.current: any): HTMLDivElement);
127
128 const handleResize = () =>
129 setIsOverflowing(container.clientWidth <= totalChildWidth);
130
131 handleResize();
132
133 // It's important to listen to the ownerDocument.defaultView to support the browser extension.
134 // Here we use portals to render individual tabs (e.g. Profiler),
135 // and the root document might belong to a different window.
136 const ownerWindow = container.ownerDocument.defaultView;
137 ownerWindow.addEventListener('resize', handleResize);
138 return () => ownerWindow.removeEventListener('resize', handleResize);
139 }, [containerRef, totalChildWidth]);
140
141 return isOverflowing;
142}
143
144// Forked from https://usehooks.com/useLocalStorage/
145export function useLocalStorage<T>(

Callers 1

OwnersStack.jsFile · 0.90

Calls 3

useStateFunction · 0.90
useLayoutEffectFunction · 0.90
handleResizeFunction · 0.85

Tested by

no test coverage detected