TanStackT
TanStack2mo ago
14 replies
full-green

cant use objects with useStore() - causes maximum update depth reached.

  const schema = z.object({
    employee_id: z.number(),
    date_range: z.object({
      start: z.date(),
      end: z.date()
    })
  });

  const form = useAppForm({
    defaultValues: {
      employee_id: 0,
      date_range: {
        start: startOfMonth(new Date()),
        end: new Date()
      }
    },
    validationLogic: revalidateLogic(),
    validators: {
      onDynamic: schema,
    },
  });


and calling a useStore on the date_range causes the following exception

Uncaught Error: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.

 const dateRange = useStore(form.store, (state) => state.values.date_range);


version:
"@tanstack/react-form": "^1.23.8"

can i work around this ?
i had a date range component
this also fails

 const dateRangeStart = useStore(form.store, (state) => state.values.date_range.start);
Was this page helpful?