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 for componentWillMount and componentWillReceiveProp being used with getDerivedStateFromProps #368

Closed
BrOrlandi opened this issue Jul 5, 2018 · 7 comments

Comments

@BrOrlandi
Copy link

Do you want to request a feature or report a bug?
bug

What is the current behavior?
The following warning is being shown when using Transition.

Warning: Unsafe legacy lifecycles will not be called for components using new component APIs.

Transition uses getDerivedStateFromProps() but also contains the following legacy lifecycles:
  componentWillMount
  componentWillReceiveProps

The above lifecycles should be removed. Learn more about this warning here:
https://fb.me/react-async-component-lifecycle-hooks`

Reproduce
To reproduce, I am using CSSTransition with TransitionGroup on the project.

What is the expected behavior?
Should not show the Warning.

Which versions, and which browser / OS are affected by this issue? Did this work in previous versions?
Version 2.4, on Chrome. This doesn't happen in version 2.1, but I think it doesn't use the new version of react.

@jquense
Copy link
Collaborator

jquense commented Jul 5, 2018

can you confirm that v2.4 is the actual version you have installed? we removed the deprecation methods this in v4: v2.3.1...v2.4.0

@BrOrlandi
Copy link
Author

Maybe is another dependency that may be using react-transition-group in a different version. I will check it out.

@BrOrlandi
Copy link
Author

I also using Recharts and Storybook, didn't know they use react-transition-group too. They are using versions prior to v2.3.1. Thanks!

@fullstackzach
Copy link

I am also getting the above message using v2.4.0. I don't have any other dependences using react-transition-group

@jquense I took a look at the compare you posted above and see that getDerivedStateFromProps() is still being used here. Maybe that is the reason for the message?

@jquense
Copy link
Collaborator

jquense commented Jul 12, 2018

I took a look at the compare you posted above and see that getDerivedStateFromProps()

getDerivedStateFromProps is what it's supposed to be, that's the new api

@fullstackzach
Copy link

@jquense my bad - I read the error message backwards. I am still getting the warning mentioned above, though for usage of componentWillMount and componentWillReceiveProps

I do see componentWillMount() used in dist/react-transition-group.js on line 951 in my node-modules, I'm guessing to polyfill for older versions of react? But I also see these flags set intended to suppress the warning message. So I would have expected the warning to be suppressed.
componentWillMount.__suppressDeprecationWarning = true;
componentWillReceiveProps.__suppressDeprecationWarning = true;

I tried doing a fresh install of node-modules and confirmed I'm installing v2.4.0

@fullstackzach
Copy link

I solved this and wanted to share my solution here, in case anyone else comes looking for an answer since the warning the console was giving me was a big red-herring.

After a lot of trial and error, I discovered that react-hot-loader v4.0.0 was the cause of the issue and upgrading to atleast 4.1.1 resolved these errors.
See gaearon/react-hot-loader#918

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

3 participants