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 about componentWillReceiveProps in React 16.9.0 #670

Closed
ChrisWiles opened this issue Aug 14, 2019 · 13 comments
Closed

Warning about componentWillReceiveProps in React 16.9.0 #670

ChrisWiles opened this issue Aug 14, 2019 · 13 comments

Comments

@ChrisWiles
Copy link

ChrisWiles commented Aug 14, 2019

react-dom.development.js:11494 Warning: componentWillReceiveProps has been renamed, and is not recommended for use. See https://fb.me/react-async-component-lifecycle-hooks 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
* Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.

Please update the following components: Autosuggest, Autowhatever

Can be auto fixed with

npx react-codemod rename-unsafe-lifecycles <path>

@wyze
Copy link

wyze commented Aug 16, 2019

Duplicate of #624.

@fatso83
Copy link

fatso83 commented Aug 23, 2019

@ChrisWiles Renaming is not a fix. That's a temporary band-aid to suppress the warning. The warning has a meaning; the method is being removed in the next major version, so you need to refactor the internals, for instance using the static getDerivedStateFromProps method to toggle flags.

@ChrisWiles
Copy link
Author

ChrisWiles commented Aug 25, 2019

You still have a while before react 17, so while you refactor your library you could at least add unsafe in the meantime which takes no time and little effort

@TheMoonDawg
Copy link

Actually, the UNSAFE_ lifecycle methods will still exist in React 17. So switching everything to use the UNSAFE prefix will make it work in React 17 as well!

@shirshendubhowmick
Copy link

Yes please add UNSAFE_ prefix while the code is being refactored. Otherwise it will break in React 17

@bdwain
Copy link

bdwain commented Sep 11, 2019

bump. @moroshko if someone made a PR to address this would you merge it? It would be great to have this fixed before react 17 comes out. otherwise this library will no longer work.

@fatso83
Copy link

fatso83 commented Sep 11, 2019

Just fork it, publish a namescoped version to the NPM registry and change your dependencies to use that. Done.

@bdwain
Copy link

bdwain commented Sep 11, 2019

@fatso83 yea that's fine temporarily but if the repo will never be updated i'll probably just look for alternatives

@mfaizan1
Copy link

react-dom.development.js:11494 Warning: componentWillReceiveProps has been renamed, and is not recommended for use. See https://fb.me/react-async-component-lifecycle-hooks 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
* Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.

Please update the following components: Autosuggest, Autowhatever

Can be auto fixed with

npx react-codemod rename-unsafe-lifecycles <path>

hello , any help regarding path , iused following path but it didn't do anything

npx react-codemod rename-unsafe-lifecycles /Users/username/Documents/react/projectname/node_modules/react-autosuggest/dist/Autosuggest.js

@rlueder
Copy link

rlueder commented Oct 23, 2019

Here's a PR that should take care of it: #681

@aberezkin
Copy link
Collaborator

Fixed in #681

@wkerswell-gresham
Copy link

@aberezkin Thanks! been waiting on this for a while now.

@peetss
Copy link

peetss commented Jul 16, 2020

@aberezkin Also thanks!

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