Handling null containerRef in child component with TanStack Virtual #852
Unanswered
bennobuilder
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
When using TanStack Virtual (
useVirtualizer
) in a child component with a scroll container ref from a parent, thecontainerRef
may be null on initial render. This issue is more apparent in production, as React's Strict Mode in development performs double renders, masking the problem.To resolve:
This
useEffect
in the child component ensures the virtualizer measures correctly once the parent'scontainerRef
is available. It's necessary because the child's initial render happens before the parent's ref is assigned, anduseRef
doesn't trigger re-renders on value changes.Note: This is not really a Q&A but an issue I experienced that I wanted to document
Beta Was this translation helpful? Give feedback.
All reactions