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

[No QA] Add new style rule for refs in constructor #2143

Merged
merged 2 commits into from
Mar 31, 2021

Conversation

roryabraham
Copy link
Contributor

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.

@roryabraham roryabraham self-assigned this Mar 29, 2021
@roryabraham roryabraham requested a review from a team as a code owner March 29, 2021 20:54
@MelvinBot MelvinBot requested review from deetergp and removed request for a team March 29, 2021 20:54
@roryabraham roryabraham changed the title Add new style rule for refs in constructor [No QA] Add new style rule for refs in constructor Mar 29, 2021
STYLE.md Outdated
super(props);

// Good: Ref is declared in the constructor
this.myRef = null;
Copy link
Contributor

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?

Copy link
Contributor Author

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.

STYLE.md Outdated Show resolved Hide resolved
@marcaaron
Copy link
Contributor

Cool with this change, but I'd prefer using undefined over null.
We should also consider updating all usages of refs in E.cash so they follow this convention after the change is made.

@roryabraham
Copy link
Contributor Author

Updated

Copy link
Contributor

@alex-mechler alex-mechler left a 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

Copy link
Contributor

@deetergp deetergp left a 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 👍

@roryabraham roryabraham mentioned this pull request Mar 30, 2021
5 tasks
@marcaaron marcaaron merged commit 88ed9c3 into master Mar 31, 2021
@marcaaron marcaaron deleted the Rory-AddRefStyleRule branch March 31, 2021 02:07
@roryabraham
Copy link
Contributor Author

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?

@roryabraham
Copy link
Contributor Author

Since there were no objections, the revert PR is here

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

Successfully merging this pull request may close these issues.

4 participants