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

Warning: Using UNSAFE_componentWillReceiveProps in strict mode is not recommended #1794

Closed
yudao opened this issue Jun 3, 2020 · 18 comments · Fixed by #3923 or #3929
Closed

Warning: Using UNSAFE_componentWillReceiveProps in strict mode is not recommended #1794

yudao opened this issue Jun 3, 2020 · 18 comments · Fixed by #3923 or #3929
Labels
react 18 issue This will need to be fixed for react 18

Comments

@yudao
Copy link

yudao commented Jun 3, 2020

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.

@epicfaace
Copy link
Member

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!

@ievgennaida
Copy link

ievgennaida commented Dec 7, 2020

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

@mrjuan1
Copy link

mrjuan1 commented Jan 18, 2021

Is there a PR for this yet?

@Link631
Copy link

Link631 commented Mar 8, 2021

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?

@dedenbangkit
Copy link

Still no fix for this issue?

@germanelnica
Copy link

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

@samuelcotterall
Copy link

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)?

@epicfaace
Copy link
Member

@jimmycallin has a slightly more complex PR #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 ?

@jimmycallin
Copy link
Collaborator

"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
Copy link
Collaborator

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.

@skysantoroa
Copy link

Any update on this?

@rmannibucau
Copy link

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.

@heath-freenome heath-freenome added the react 18 issue This will need to be fixed for react 18 label Aug 30, 2022
@hickscorp
Copy link

Is there any status update on this issue?

@the-blue-coder
Copy link

The issue is still present

@modellking
Copy link

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

heath-freenome added a commit to heath-freenome/react-jsonschema-form that referenced this issue Oct 28, 2023
… items

Fixes rjsf-team#3924 by defaulting to an empty object for the `itemSchema` when undefined
Fixes rjsf-team#3927 by fixing `getSnapshotBeforeUpdate()` added for the fix rjsf-team#1794
- In `@rjsf/core` updated `ArrayField`'s `renderFixedArray()` to default the `itemSchema` to an empty object if it is falsy
  - Updated the tests for `ArrayField` to verify the fix
  - Updated the `getSnapshotBeforeUpdate()` to diff the old and new props and to set the `shouldUpdate` prop if the old and new state differs
- Updated `CHANGELOG.md` accordingly
  - Also added entry for the fix for rjsf-team#3919
heath-freenome added a commit to heath-freenome/react-jsonschema-form that referenced this issue Oct 28, 2023
… items

Fixes rjsf-team#3924 by defaulting to an empty object for the `itemSchema` when undefined
Fixes rjsf-team#3927 by fixing `getSnapshotBeforeUpdate()` added for the fix rjsf-team#1794
- In `@rjsf/core` updated `ArrayField`'s `renderFixedArray()` to default the `itemSchema` to an empty object if it is falsy
  - Updated the tests for `ArrayField` to verify the fix
  - Updated the `getSnapshotBeforeUpdate()` to diff the old and new props and to set the `shouldUpdate` prop if the old and new state differs
- Updated `CHANGELOG.md` accordingly
  - Also added entry for the fix for rjsf-team#3919
heath-freenome added a commit to heath-freenome/react-jsonschema-form that referenced this issue Oct 28, 2023
… items

Fixes rjsf-team#3924 by defaulting to an empty object for the `itemSchema` when undefined
Fixes rjsf-team#3927 by fixing `getSnapshotBeforeUpdate()` added for the fix rjsf-team#1794
- In `@rjsf/core` updated `ArrayField`'s `renderFixedArray()` to default the `itemSchema` to an empty object if it is falsy
  - Updated the tests for `ArrayField` to verify the fix
  - Updated the `getSnapshotBeforeUpdate()` to diff the old and new props and to set the `shouldUpdate` prop if the old and new state differs
- Updated `CHANGELOG.md` accordingly
  - Also added entry for the fix for rjsf-team#3919
heath-freenome added a commit that referenced this issue Oct 30, 2023
…3929)

Fixes #3924 by defaulting to an empty object for the `itemSchema` when undefined
Fixes #3927 by fixing `getSnapshotBeforeUpdate()` added for the fix #1794
- In `@rjsf/core` updated `ArrayField`'s `renderFixedArray()` to default the `itemSchema` to an empty object if it is falsy
  - Updated the tests for `ArrayField` to verify the fix
  - Updated the `getSnapshotBeforeUpdate()` to diff the old and new props and to set the `shouldUpdate` prop if the old and new state differs
- Updated `CHANGELOG.md` accordingly
  - Also added entry for the fix for #3919
@iwan-uschka
Copy link

iwan-uschka commented Nov 12, 2023

Fixed (using version 5.13.6). Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
react 18 issue This will need to be fixed for react 18
Projects
None yet