Rule suggestion: no-state-in-constructor
See original GitHub issueINCORRECT
class MyComponent extends Component {
constructor(props) {
super(props);
this.state = {
counter: props.initialValue
};
}
}
CORRECT
class MyComponent extends Component {
state = {
counter: this.props.initialValue
};
}
Why? It may reduce boilerplate by not having to define a constructor just for initializing the state.
What do you think about this?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:5
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Rule suggestion: no-state-in-constructor · Issue #1810 - GitHub
Just today my workmate suggested a similar idea - forbidding constructor in React components altogether. The rationale for this is that it's ...
Read more >Rule 52. Findings and Conclusions by the Court; Judgment on ...
In granting or refusing an interlocutory injunction, the court must similarly state the findings and conclusions that support its action. (3) For a...
Read more >Rule 25 allows 90 days after the suggestion of death ... - GovInfo
Rule 25 allows 90 days after the suggestion of death for a motion for substitution. 1. Fed.R.Civ.P. 25(a)(1). IN THE UNITED STATES DISTRICT...
Read more >Rule 52 - Findings and Conclusions by the Court; Judgment ...
In granting or refusing an interlocutory injunction, the court must similarly state the findings and conclusions that support its action. (3) For a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yeah. Let me try this out. I’ll open a PR once I got something.
That’s true. Issue #626 in this repo suggests such a rule, but it hasn’t happened yet.