File tree 1 file changed +10
-6
lines changed
packages/form-js-viewer/src/render/components/form-fields
1 file changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -277,13 +277,19 @@ function DownloadButton(props) {
277
277
278
278
/**
279
279
*
280
- * @param {import("preact").RefObject<HTMLElement> } ref
280
+ * @param {import("preact").RefObject<HTMLElement|null > } ref
281
281
* @returns boolean
282
282
*/
283
283
function useInViewport ( ref ) {
284
284
const [ isInViewport , setIsInViewport ] = useState ( false ) ;
285
285
286
286
useEffect ( ( ) => {
287
+ const container = ref . current ;
288
+
289
+ if ( ! container ) {
290
+ return ;
291
+ }
292
+
287
293
const observer = new IntersectionObserver (
288
294
( [ entry ] ) => {
289
295
if ( entry . isIntersecting ) {
@@ -295,13 +301,11 @@ function useInViewport(ref) {
295
301
} ,
296
302
) ;
297
303
298
- if ( ref . current ) {
299
- observer . observe ( ref . current ) ;
300
- }
304
+ observer . observe ( container ) ;
301
305
302
306
return ( ) => {
303
- if ( ref . current ) {
304
- observer . unobserve ( ref . current ) ;
307
+ if ( container ) {
308
+ observer . unobserve ( container ) ;
305
309
}
306
310
} ;
307
311
} , [ ref ] ) ;
You can’t perform that action at this time.
0 commit comments