Skip to content

Commit 413c082

Browse files
committed
refactor: remove warnings
1 parent 769a2a6 commit 413c082

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

packages/form-js-viewer/src/render/components/form-fields/DocumentPreview.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -277,13 +277,19 @@ function DownloadButton(props) {
277277

278278
/**
279279
*
280-
* @param {import("preact").RefObject<HTMLElement>} ref
280+
* @param {import("preact").RefObject<HTMLElement|null>} ref
281281
* @returns boolean
282282
*/
283283
function useInViewport(ref) {
284284
const [isInViewport, setIsInViewport] = useState(false);
285285

286286
useEffect(() => {
287+
const container = ref.current;
288+
289+
if (!container) {
290+
return;
291+
}
292+
287293
const observer = new IntersectionObserver(
288294
([entry]) => {
289295
if (entry.isIntersecting) {
@@ -295,13 +301,11 @@ function useInViewport(ref) {
295301
},
296302
);
297303

298-
if (ref.current) {
299-
observer.observe(ref.current);
300-
}
304+
observer.observe(container);
301305

302306
return () => {
303-
if (ref.current) {
304-
observer.unobserve(ref.current);
307+
if (container) {
308+
observer.unobserve(container);
305309
}
306310
};
307311
}, [ref]);

0 commit comments

Comments
 (0)