React-router: Replace componentWillMount by UNSAFE_componentWillMount for v3

Created on 14 Aug 2019  路  8Comments  路  Source: ReactTraining/react-router

Expected Behavior

React shouldn't warn about deprecated lifecycle methods

Actual Behavior

React does warn and react-router 3 isn't going to be supported in a next major version of React

Most helpful comment

I pushed up a PR here: https://github.com/ReactTraining/react-router/pull/6883 that also maintains backwards compatibility.

@timdorr please let me know if you're okay with the approach

All 8 comments

Same with componentWillReceiveProps. I get the following console warnings:

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: Router
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: Router

Can someone submit a PR?

Actually, this is an interesting one because we might break compat with older versions of react if we change the names. We can bump the minor to make it slightly easy, but most folks have caret version selectors and will get that version included.

What does everyone think we should do here?

What does everyone think we should do here?

Since router 3 is going to be used by many projects for many years I think it may be a good practice to publish a separate package called react-router-3. Thoughts?

I just did a quick check and found no occurrences of componentWillReceiveProps or other unsafe methods in the latest versions of RR. Maybe we should release a legacy version of RRv3 without the unsafe methods?

Same issue

I pushed up a PR here: https://github.com/ReactTraining/react-router/pull/6883 that also maintains backwards compatibility.

@timdorr please let me know if you're okay with the approach

3.2.4 is out to fix this: npm install react-router@previous

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stnwk picture stnwk  路  3Comments

Waquo picture Waquo  路  3Comments

yormi picture yormi  路  3Comments

winkler1 picture winkler1  路  3Comments

davetgreen picture davetgreen  路  3Comments