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

Warning: Using UNSAFE_componentWillReceiveProps in strict mode is not recommended

Open yudao opened this issue 5 years ago • 14 comments

Hi!

I have an old bug see here but i'm with the last version.

I know that the warning is not raised in production but normally this bug was fixed in the 2.0 version, isn't it ?

I'm only reusing one Form component and only change data and uischema for each schema I have in my multistep form.

Description

index.js:1 Warning: Using UNSAFE_componentWillReceiveProps in strict mode is not recommended and may indicate bugs in your code. See https://fb.me/react-unsafe-component-lifecycles for details.

  • Move data fetching code or side effects to componentDidUpdate.
  • If you're updating state whenever props change, refactor your code to use memoization techniques or move it to static getDerivedStateFromProps. Learn more at: https://fb.me/react-derived-state

Please update the following components: Form

Version

react: 16.13.1 @rjsf/core: 2.0.1

Cheers, Yu.

yudao avatar Jun 03 '20 17:06 yudao

Yes, we still use UNSAFE_componentWillReceiveProps in 2.0 -- the only thing that was fixed was removing a few instances of this method, and mostly just renaming componentWillReceiveProps -> UNSAFE_ componentWillReceiveProps. If you'd like to help with refactoring to remove it, that would be very much appreciated!

epicfaace avatar Jun 15 '20 13:06 epicfaace

I have the same warning. Would be nice to avoid it.

ievgennaida avatar Dec 07 '20 12:12 ievgennaida

Is there a PR for this yet?

mrjuan1 avatar Jan 18 '21 10:01 mrjuan1

It doesn't look like it yet. More info on a fix:

https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops https://itnext.io/react17-or-how-to-get-rid-of-componentwillreceiveprops-c91f9a6f6f03

caseyjhol avatar Jan 18 '21 16:01 caseyjhol

Hi, I found the same warning.

When can the checkin be expected in a release and will it fix this Issue so that the warning disappears?

Link631 avatar Mar 08 '21 02:03 Link631

Still no fix for this issue?

dedenbangkit avatar Mar 17 '21 07:03 dedenbangkit

I think issue is still there. Is there a way to fix it?

rocknatt avatar Apr 01 '21 12:04 rocknatt

this is the commit with the fix https://github.com/mrjuan1/react-jsonschema-form/commit/0dd427d5368db4ca9458c77fca79887d48a0d748

germanelnica avatar Apr 08 '21 23:04 germanelnica

this is the commit with the fix mrjuan1@0dd427d

Maybe I’m being dumb, but I can’t see a PR for this (neither open nor closed)?

samuelcotterall avatar Jul 18 '21 08:07 samuelcotterall

@jimmycallin has a slightly more complex PR https://github.com/rjsf-team/react-jsonschema-form/pull/2010 that does this, though maybe https://github.com/mrjuan1/react-jsonschema-form/commit/0dd427d5368db4ca9458c77fca79887d48a0d748 would just work as a simpler solution instead? What do you think @jimmycallin ?

epicfaace avatar Jul 18 '21 15:07 epicfaace

"slightly more complex" is surely an understatement. If it works, I'm happy! I'll see if I can figure out why I thought the refactorings were necessary.

jimmycallin avatar Jul 18 '21 18:07 jimmycallin

Ok, I just looked into the commit and it won't work unfortunately, for the reasons that caused me to introduce the necessary refactorings.

image

On line 45 you can see that it calls a class method using this.getStateFromProps. Since it's a static method, this is not allowed. Once you start to break out all logic related to this.getStateFromProps, you will probably end up with a PR similar to my #2010.

jimmycallin avatar Jul 21 '21 22:07 jimmycallin

Any update on this?

skysantoroa avatar Jun 28 '22 08:06 skysantoroa

up? We now have react 18 out and this issue popped up in a previous major release so it would be neat to fix it.

rmannibucau avatar Aug 25 '22 10:08 rmannibucau

Is there any status update on this issue?

hickscorp avatar May 25 '23 23:05 hickscorp

The issue is still present

the-blue-coder avatar May 28 '23 17:05 the-blue-coder

Is this on the roadmap? Do you require external contribution?

modellking avatar Oct 05 '23 10:10 modellking

Fixed (using version 5.13.6). Thanks!

iwan-uschka avatar Nov 12 '23 21:11 iwan-uschka