question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 5 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
horntacommented, Nov 29, 2018

I can confirm this works in the latest release 7.11.0

1reaction
metreniukcommented, Aug 29, 2018

By the way the impossible order of getDerivedStateFromProps issue seems to be fixed in GH-1858.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found