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

Avoid using deprecated/UNSAFE_* React methods #519

Closed
10 tasks done
BPScott opened this issue Oct 4, 2018 · 3 comments
Closed
10 tasks done

Avoid using deprecated/UNSAFE_* React methods #519

BPScott opened this issue Oct 4, 2018 · 3 comments
Assignees
Milestone

Comments

@BPScott
Copy link
Member

BPScott commented Oct 4, 2018

React has deprecated its use of a selection of lifecycle methods it has deemed to be unsafe.

The componentWillMount, componentWillReceiveProps and componentWillUpdate lifecycle methods have the potential to cause headaches and We should use the newer, more stable lifecycle methods of getDerivedStateFromProps and getSnapshotBeforeUpdate instead.

We could shuffle onto using UNSAFE_componentWillMount etc but that doesn't fix the root problem.

The good news is ESLint now warns about our usage of these methods so we no longer have to think about this when doing PR reviews, however there are still a few places in existing code where they are used. Any existing use of these functions should be removed


Search the codebase for react/no-deprecated and refactor the usage of the componentWillMount, componentWillReceiveProps and componentWillUpdate to use the new lifecycle functions.

As of 2018-10-04, searching the codebase for react/no-deprecated shows the following Components are affected:

@BPScott BPScott transferred this issue from another repository Oct 31, 2018
@ghost
Copy link

ghost commented Oct 31, 2018

👋 Thanks for opening your first issue. A contributor should give feedback soon. If you haven’t already, please check out the contributing guidelines. You can also join #polaris on the Shopify Partners Slack.

@BPScott
Copy link
Member Author

BPScott commented Feb 21, 2019

Following an update to eslint-plugin-react in jsx-eslint/eslint-plugin-react#2069 componentWillMount, componentWillReceiveProps and componentWillUpdate will not trigger a react/no-deprecated warning as they are considered legacy componenets but they're not officially deprecated just yet.

We should still move away from them.

@BPScott
Copy link
Member Author

BPScott commented Jun 12, 2019

Enabling react/no-unsafe with checkAliases: true option shall complain if we try and use and of the unsafe lifecycle methods, including the unprefixed versions

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

4 participants