Deprecated lifecycle method warnings with React 16.9
The following warning is shown upon upgrading to React 16.9.0:
Error: Warning: componentWillMount has been renamed, and is not recommended for use. See https://fb.me/react-async-component-lifecycle-hooks for details.
* Move code with side effects to componentDidMount, and set initial state in the constructor.
* Rename componentWillMount to UNSAFE_componentWillMount 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: Select in src/tests.entry.js (line 294578)
I've got similar warning related to this one
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: AutosizeInput, Select
That means you have component using legacy lifecycle OR you are using a library which uses the legacy lifecycle, I don't see this as an issue, in fact, it is helpful to identify legacy code and warn you when you do use libraries that do still.
@jairusd react-select is the library with legacy methods.
@JedWatson, since react 16.9.0 started to show a warning for deprecated lifecycles, is it possible that you create a patch release with a quick fix of renaming the deprecated lifecycles in order to remove the warning?
I've created a pull request (PR) for this: https://github.com/JedWatson/react-select/pull/3716
Note that this is just a quick fix for now to remove the warnings. It still requires a fix to move the code from the deprecated lifecycles to other related lifecycles.
Thanks
oh sorry guys i was drunk when i made that comment
What about running npx react-codemod rename-unsafe-lifecycles, will it work for libraries installed in node_modules?
@tonix-tuft, I doubt if it would. If it does, it will be overwritten on your next npm ci or npm install
By the way, my PR was merged to master. Just waiting for the next release
@rj-david thanks!
@tonix-tuft I ran npx react-codemod rename-unsafe-lifecycles where the warning was shown node_modules/react-dom ... but no results:
cs@cs-swift:~/work/react-best-practices/node_modules/react-dom$ npx react-codemod rename-unsafe-lifecycles
? On which files or directory should the codemods be applied? .
? Which dialect of JavaScript do you use? JavaScript
Executing command: jscodeshift --verbose=2 --ignore-pattern=**/node_modules/** --parser babel --extensions=jsx,js --transform /home/cs/.npm/_npx/31217/lib/node_modules/react-codemod/transforms/rename-unsafe-lifecycles.js .
Processing 36 files...
Spawning 3 workers...
Sending 12 files to free worker...
Sending 12 files to free worker...
Sending 12 files to free worker...
SKIP index.js
SKIP profiling.js
SKIP server.js
SKIP server.node.js
SKIP server.browser.js
SKIP test-utils.js
SKIP unstable-fizz.browser.js
SKIP unstable-fizz.js
SKIP unstable-fizz.node.js
SKIP unstable-native-dependencies.js
SKIP umd/react-dom-unstable-fizz.browser.development.js
SKIP cjs/react-dom-unstable-fizz.browser.development.js
SKIP umd/react-dom-unstable-fizz.browser.production.min.js
SKIP cjs/react-dom-unstable-fizz.browser.production.min.js
SKIP cjs/react-dom-unstable-fizz.node.development.js
SKIP cjs/react-dom-unstable-fizz.node.production.min.js
SKIP umd/react-dom-test-utils.production.min.js
SKIP cjs/react-dom-test-utils.production.min.js
SKIP umd/react-dom-unstable-native-dependencies.production.min.js
SKIP cjs/react-dom-unstable-native-dependencies.production.min.js
SKIP cjs/react-dom-server.browser.production.min.js
SKIP umd/react-dom-server.browser.production.min.js
SKIP cjs/react-dom-server.node.production.min.js
SKIP cjs/react-dom-test-utils.development.js
SKIP umd/react-dom-test-utils.development.js
SKIP cjs/react-dom-unstable-native-dependencies.development.js
SKIP umd/react-dom-unstable-native-dependencies.development.js
SKIP cjs/react-dom-server.browser.development.js
SKIP cjs/react-dom.profiling.min.js
SKIP cjs/react-dom.production.min.js
SKIP cjs/react-dom-server.node.development.js
SKIP umd/react-dom.production.min.js
SKIP umd/react-dom.profiling.min.js
SKIP umd/react-dom-server.browser.development.js
SKIP cjs/react-dom.development.js
SKIP umd/react-dom.development.js
All done.
Results:
0 errors
0 unmodified
36 skipped
0 ok
Time elapsed: 17.457seconds
even using this "npx react-codemod rename-unsafe-lifecycles" ,the warning still persists..what should i do to avoid this warning?
@gwyneplaine when can we expect this for a new release? Thanks
the latest version of react-moment is also a library with this issue
@zhenyu0519, is that package a dependency of this package?
oops. wrongs repo...
@zhenyu0519, is that package a dependency of this package?
Sorry. I don't know what I was thinking. It's not.
Thanks @gwyneplaine for merging #3716. Would you mind cutting a release with the change?
Also, is there any chance you're in touch with Jed and could help us get a similar fix for his other project, https://github.com/JedWatson/react-input-autosize/issues/163?
I have same warning. I re-implement my component using react hooks but the warning is still showing. Anyone have same issue. These warning should not be shown in functional component.
looking forward to see #3716 published to npm for the time being so my console is less cluttered! tnx everyone!
+1 to hoping for a release soon to get rid of these. We've cleared out all of ours in our app, but waiting for all these dependencies to catch up so I can reclaim my console again.