Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React crash when setting defaultValue on conditionally rendered Field. #1134

Open
asegarra opened this issue Jan 30, 2025 · 0 comments
Open

Comments

@asegarra
Copy link

Describe the bug

React crashes if you set a Field level defaultValue on a conditionally rendered Field.

 Cannot update a component (`App`) while rendering a different component (`Field`). To locate the bad setState() call inside `Field`, follow the stack trace as described in https://react.dev/link/setstate-in-render 
    at Field (https://tkj4dz.csb.app/node_modules/@tanstack/react-form/dist/esm/useField.js:43:23)
    at APIField
    at div
    at form
    at div
    at App

Your minimal, reproducible example

https://codesandbox.io/p/sandbox/optimistic-golick-tkj4dz

Steps to reproduce

  1. Type something in First name so last name gets rendered

Expected behavior

Should not crash

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • OS: Windows 10

TanStack Form adapter

None

TanStack Form version

v0.41.3

TypeScript version

No response

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant