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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

FieldArray change triggers validation twice #2170

Open
liupy525 opened this issue Jan 4, 2020 · 4 comments
Open

FieldArray change triggers validation twice #2170

liupy525 opened this issue Jan 4, 2020 · 4 comments
Labels

Comments

@liupy525
Copy link

liupy525 commented Jan 4, 2020

馃悰 Bug report

Current Behavior

When Field in FieldArray changed, the validate of Field was triggered twice.
Take a look into example in code sandbox.

Expected behavior

Validation happens only once.

Reproducible example

https://codesandbox.io/s/formik-fieldarray-change-validation-bug-8m6l4

Suggested solution(s)

Additional context

Your environment

Software Version(s)
Formik 2.1.1
React 16.12.0
TypeScript
Browser
npm/Yarn
Operating System
@mrmuhammadali
Copy link
Contributor

I don't know if it's desired behavior but I'm able to figure out what changes were committed which caused this:
v2.0.7...v2.0.8#diff-5726f9052216350a9c64a497cd89e4bb
It might be helpful to solve this issue.
@jaredpalmer

@pietmichal
Copy link

pietmichal commented Oct 23, 2020

I've noticed that this is happening when a change happens within an element of the array.

for example

foo: [
  { bar: "" } // updating value of `bar` runs validation two times in a row
]

@pietmichal
Copy link

pietmichal commented Oct 23, 2020

I've digged deeper and now I am seeing a pattern.

The amount of validations is equal to the amount of <FieldArray>'s preceding <Field>.

I've made a codesandbox demonstrating this: https://codesandbox.io/s/form-fieldarray-multiple-validation-bug-frxk1

This impacts component's performance because the amount of validations co-relates the amount of re-renders.

@antonioorct
Copy link

Any updates or workarounds for this?

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

No branches or pull requests

4 participants