sort-comp: Impossible order of getDerivedStateFromProps, state and constructor
See original GitHub issue static getDerivedStateFromProps() {}
constructor(props) {}
state = {};
Above code reports
getDerivedStateFromProps should be placed after state
So I change the code
constructor(props) {}
state = {};
static getDerivedStateFromProps() {}
getDerivedStateFromProps should be placed before constructor
Also, the state property must be placed after the constructor. Something doesn’t make sense here.
'error',
{
order: ['static-methods', 'lifecycle', 'everything-else', 'render'],
groups: {
lifecycle: [
'displayName',
'propTypes',
'contextTypes',
'childContextTypes',
'mixins',
'statics',
'defaultProps',
'constructor',
'getDefaultProps',
'state',
'getInitialState',
'getChildContext',
'getDerivedStateFromProps',
'componentWillMount',
'UNSAFE_componentWillMount',
'componentDidMount',
'componentWillReceiveProps',
'UNSAFE_componentWillReceiveProps',
'shouldComponentUpdate',
'componentWillUpdate',
'UNSAFE_componentWillUpdate',
'getSnapshotBeforeUpdate',
'componentDidUpdate',
'componentDidCatch',
'componentWillUnmount'
]
}
}
]```
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
sort-comp: Impossible order of getDerivedStateFromProps ...
static getDerivedStateFromProps() {} constructor(props) {} state = {}; Above code reports getDerivedStateFromProps should be placed after ...
Read more >reactjs - How to fix warning caused by Flow Function Types ...
But I'm unable to fix the warning. I want the Function Types before constructor the same as the other Type Definition. How can...
Read more >React.js static getDerivedStateFromProps() - GeeksforGeeks
The getDerivedStateFromProps() method is used when the state of a component depends on changes of props. getDerivedStateFromProps(props ...
Read more >eslint-config-imweb - npm
Rule Name:@typescript-eslint/no-useless-constructor ["warn"] ... is disallowed in strict mode because it makes code impossible to predict and optimize."}].
Read more >ESLint | John Vincent
This ESLint discussion is an addition to Visual Studio Code. ESLint. ESLint · ESLint Rules · ESLint User Guide. Prettier.
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
I can confirm this works in the latest release 7.11.0
By the way the impossible order of getDerivedStateFromProps issue seems to be fixed in GH-1858.