Skip to content
Discussion options

You must be logged in to vote

Yes, you can combine them. The trick is to only render <Field> components for the rows that are currently visible in the virtual window, rather than mounting all 100+ fields at once.

Here's the general approach using TanStack Virtual + TanStack Form:

import { useVirtualizer } from '@tanstack/react-virtual'
import { useForm } from '@tanstack/react-form'

function VirtualizedForm() {
  const form = useForm({
    defaultValues: {
      rows: Array.from({ length: 500 }, (_, i) => ({
        name: `Item ${i}`,
        quantity: 0,
        price: 0,
      })),
    },
    onSubmit: ({ value }) => console.log(value),
  })

  const parentRef = useRef<HTMLDivElement>(null)

  const virtualizer = us…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by pedro757
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