Skip to content
Source
Sign inSign up
TanStack/form

Async initial array values are not set #2178

ClosedeTallang(GitHub profile, opens in a new tab) opened this issue 2 comments

Describe the bug

Until version 1.31.0, it's been possible to set async initial values that are in the form of an array. In version 1.32.0, this does not seem to work anymore. I assume this PR is the reason, however I've not looked into it.

Your minimal, reproducible example

https://stackblitz.com/edit/tanstack-form-skfjtgfa?file=src%2Findex.tsx

Steps to reproduce

  1. Open the StackBlitz
  2. Notice that no person is displayed after 3 seconds, when the async state is updated
  3. You may click the "Add person"-button to notice that there suddenly is 2 persons in the list

Expected behavior

When the async state is resolved, I would expect the state to be updated in the form as well. This works up until version 1.31.0.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • OS: macOS
  • Browser: Chrome

TanStack Form adapter

react-form

TanStack Form version

1.32.0

TypeScript version

6.0.3

Additional context

No response

  1. @eTallang, is there a specific reason for maintaining separate state here instead of directly using form.setFieldValue?

    form.setFieldValue('people', [
            {
              age: 24,
              name: 'Ben',
            },
          ]);
  2. @mudasirpandith I'm not sure I follow. The issue has to deal with asynchronous state, so I assume in your code example that form.setFieldValue would be called in a useEffect, which is not ideal. Not to mention, it should not be necessary since TanStack Form handles these cases automatically, according to the docs: https://tanstack.com/form/latest/docs/framework/react/guides/async-initial-values

Sign in to join this conversation.