Skip to content

sort-comp: Impossible order of getDerivedStateFromProps, state and constructor #1839

@hornta

Description

@hornta
 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' ] } } ]``` 

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions