From 91df9306ed99467cf5baadfe2a4e095249a63816 Mon Sep 17 00:00:00 2001 From: Erik Pehrers Date: Thu, 13 Jul 2023 08:47:24 +0200 Subject: [PATCH] Suppress even tho https://github.com/facebook/react/pull/26395 --- src/index.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/index.tsx b/src/index.tsx index f4f2c42..3a09f86 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,6 +1,7 @@ import React, { useRef, useState, + useEffect, useLayoutEffect, useCallback, useMemo, @@ -81,6 +82,9 @@ function stylesForItem({ const lastKnownHeights = {} as Record; +const useIsomorphicLayoutEffect = + typeof window !== 'undefined' ? useLayoutEffect : useEffect; + export function SnappyReactGrid({ id = 'default', items, @@ -173,7 +177,7 @@ export function SnappyReactGrid({ } }, [updateItemVisibility, onScroll]); - useLayoutEffect(() => { + useIsomorphicLayoutEffect(() => { styleCache.current = {}; updateItemVisibility();