CAIDA / charthouse-ui

Web application UI for the Hi3 project (https://hicube.caida.org)
Other
1 stars 0 forks source link

Deprecating `componentWillMount` and `componentWillReceiveProps` #15

Open digizeph opened 4 years ago

digizeph commented 4 years ago
Warning: componentWillMount has been renamed, and is not recommended for use. See 

* 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: BrowserRouter, Route, Router, Switch

componentWillMount

componentWillReceiveProps

digizeph commented 4 years ago

@JayWebz what's your opinion on this? Should it be a priority to fix?

JayWebz commented 4 years ago

Looks like they will continue to work for now with React 16.x (16.12 just came out last month), but into React 17, they will need to be updated to at least be UNSAFE methods. React blog says running a command "npx react-codemod rename-unsafe-lifecycles" (change out npx for npm or yarn) will go through a project and rename deprecated components to UNSAFE_componentWill... which will resolve the warning for now. Come react 17, these lifecycle events won't work without the UNSAFE prefix. The exact date for react 17 release isn't known yet it looks like, currently on 16.12. The short term solution of renaming to UNSAFE should probably be implemented sooner than later. The long-term solution of converting things to their new proper lifecycle method should be scheduled to happen but not doing it before 17 is released "shouldn't" break anything.

as a side note, now that React Hooks are released and starting to be more widely adopted, react is starting to hint at transitioning off of class-based components, they are supported just fine for the foreseeable future though.