Skip to content

Is there anyway to avoid the absolute positioning of virtualized items? #476

Answered by piecyk
lexahall asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, rather to position each element we can move it as whole group. We use this approach for table, where we can't position absolute rows.

const List = () => {
  const virtualizer = useWindowVirtualizer({
    count: 1000,
    estimateSize: () => 24,
  })

  const items = virtualizer.getVirtualItems()

  const [paddingTop, paddingBottom] =
    items.length > 0
      ? [
          Math.max(0, items[0].start - virtualizer.options.scrollMargin),
          Math.max(0, virtualizer.getTotalSize() - items[items.length - 1].end),
        ]
      : [0, 0]

  return (
    <div>
      <div
        style={{
          paddingTop,
          paddingBottom,
        }}
      >
        {items.map((item) => (

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@lexahall
Comment options

Answer selected by lexahall
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants