react-final-form icon indicating copy to clipboard operation
react-final-form copied to clipboard

Warning: Cannot update a component (`ForwardRef(Field)`) while rendering a different component (`ForwardRef(Field)`)

Open slowselfip opened this issue 5 years ago • 10 comments
trafficstars

Are you submitting a bug report or a feature request?

Bug report

What is the current behavior?

A react warning about "invalid set state in render" is shown when rendering the value of a conditionally rendered field that has an initialValue set.

What is the expected behavior?

That React does not print warnings in the console.

Sandbox Link

https://codesandbox.io/s/tender-sea-6fmu3?fontsize=14&hidenavigation=1&theme=dark

What's your environment?

{
  "react": 16.13.1,
  "react-dom": 16.13.1,
  "react-final-form": 6.5.1,
  "react-scripts": 3.4.1, 
  "final-form": 4.20.1
}

Other information

Note that the example is a bit contrived and that the real life scenario causing is a bit more complex.

This issue might be related to https://github.com/final-form/react-final-form/issues/828. That issue is regarding a FormSpy and this is related to a conditionally rendered Field with initialValue prop.

Thanks for taking the time and hope this can help in some way.

slowselfip avatar Aug 25 '20 10:08 slowselfip

Any news on this?

pmartiner avatar Sep 29 '21 20:09 pmartiner

I still see the same warning. I hope it will be fixed.

Warrior109 avatar Oct 06 '21 05:10 Warrior109

+1

jaryway avatar Dec 09 '21 01:12 jaryway

+1

navinleon avatar Feb 15 '22 18:02 navinleon

any news on this?

sophiabarclay avatar Jun 07 '22 11:06 sophiabarclay

This is still an issue. Complex validation functions that might not be dependent directly on form value/values but on additional data, would still throw that warning when following the documentation and changing the key of the field. In a state of React where we can simply memoize the validate function, we don't even need final form to do that for us.

kure- avatar Jun 17 '22 14:06 kure-

If it's related to validation and you have validation on individual form fields, try using record-level validation instead:

https://codesandbox.io/s/github/final-form/react-final-form/tree/master/examples/record-level-validation

antonvialibri1 avatar Jul 19 '22 14:07 antonvialibri1

I still see the same warning. I hope it will be fixed.

ws-0925 avatar Dec 22 '22 13:12 ws-0925

We have the same error with validators that return a promise.

sanex3339 avatar Mar 17 '23 10:03 sanex3339

Please see the workaround at https://github.com/final-form/react-final-form/issues/985#issuecomment-1363973861

gertdreyer avatar Apr 20 '23 18:04 gertdreyer