-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Group static lifecycle methods under lifecycle #1962
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
base: master
Are you sure you want to change the base?
Group static lifecycle methods under lifecycle #1962
Conversation
@alexzherdev what do you think about this? Is it accurate to do so or this is a breaking change that isn't worth doing? |
It's definitely a breaking change; it'd be ideal to ship this now under an option, and then we can flip the option in the next major if desired. |
Since the current behavior was intended to allow the same method to be part of multiple groups I am willing to keep this as it is. At the same time there could be different opinions about where a method should be (ex: |
@metreniuk sorry, I don't have a lot of experience with this rule. |
@alexzherdev sure. I've added the new functionality under the |
'class Hello extends React.Component {', | ||
' constructor() {}', | ||
' static getDerivedStateFromProps() {}', | ||
'}' | ||
].join('\n') | ||
].join('\n'), | ||
options: [{preferLifecycle: true}] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of modifying this test, can we duplicate it and modify the duplicate?
59af733
to
865ed16
Compare
069314a
to
181c68f
Compare
380e32c
to
51d342b
Compare
Since the lifecycle group is a special group that deals with state/props changes, grouping static lifecycle methods under lifecycle group helps to have this logic together. This looks like a good default behavior that follows the docs.
This PR enforces static lifecycle methods to be grouped under
lifecycle
group as one of possible solutions suggested by @ljharb .