-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
[No QA] Add new style rule for refs in constructor #2143
Conversation
STYLE.md
Outdated
super(props); | ||
|
||
// Good: Ref is declared in the constructor | ||
this.myRef = null; |
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.
Why null
and not undefined
? Does it make any difference?
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.
No big difference, and I have no preference.
Cool with this change, but I'd prefer using |
Updated |
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.
Big fan of this change. It makes the code far easier to read
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.
Makes sense to me 👍
Coming from here ... @tgolen makes a pretty good case that this rule adds lines of code that don't have any effect, so should be remove. The purpose of this change was to improve readability, which is subjective. Since it's not unanimous that this is beneficial, I think we should revert. Does anyone disagree? |
Since there were no objections, the revert PR is here |
I'm proposing the addition of a new React style rule. I believe that having all refs be declared in the constructor is good for documentation purposes and makes it easier to quickly figure out how a component works. Tagging a small sampling of people I know are pretty good with React to see if people agree.