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

Replace componentWillMount by UNSAFE_componentWillMount for v3 #6871

Closed
finom opened this issue Aug 14, 2019 · 8 comments
Closed

Replace componentWillMount by UNSAFE_componentWillMount for v3 #6871

finom opened this issue Aug 14, 2019 · 8 comments

Comments

@finom
Copy link

finom commented Aug 14, 2019

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

@akinnee
Copy link

akinnee commented Aug 14, 2019

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

@timdorr
Copy link
Member

timdorr commented Aug 14, 2019

Can someone submit a PR?

@timdorr
Copy link
Member

timdorr commented Aug 14, 2019

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?

@finom
Copy link
Author

finom commented Aug 15, 2019

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?

@MeiKatz
Copy link
Contributor

MeiKatz commented Aug 16, 2019

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?

@ddzy
Copy link

ddzy commented Aug 19, 2019

Same issue

@liuyenwei
Copy link

I pushed up a PR here: #6883 that also maintains backwards compatibility.

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

@timdorr
Copy link
Member

timdorr commented Aug 23, 2019

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

@timdorr timdorr closed this as completed Aug 23, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants