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.

react/sort-comp: getDerivedStateFromProps

See original GitHub issue

After updating to v17, I am getting 'getDerivedStateFromProps should be placed after componentDidUpdate`. I want to say previously in v16 the rule was below the constructor… does the new placement make sense?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7

github_iconTop GitHub Comments

2reactions
ljharbcommented, Jul 2, 2018

Yes - the bug was in eslint-plugin-react (you’d see the change on v16 as well, with a fully updated eslint-plugin-react). Specifically, gDSFP is both a static method and a lifecycle method, and the sorting logic was wrong.

See https://github.com/yannickcr/eslint-plugin-react/pull/1795 / https://github.com/yannickcr/eslint-plugin-react/issues/1793

1reaction
ljharbcommented, Jul 3, 2018

Since lifecycle is primarily for instance methods, i think it would be in “statics”

Read more comments on GitHub >

github_iconTop Results From Across the Web

sort-comp: Impossible order of getDerivedStateFromProps ...
@ljharb I made a PR (GH-1962) that enforces static lifecycles to be grouped under the lifecycle group. This seems the most reasonable behavior ......
Read more >
React.Component
These methods are called in the following order when a component is being re-rendered: static getDerivedStateFromProps(); shouldComponentUpdate(); render() ...
Read more >
Why getDerivedStateFromProps does not allow to re- ...
I use a setState right after this data.splice in order to tigger the component update and, if I scope componentDidUpdate() I saw the...
Read more >
React.js static getDerivedStateFromProps()
The getDerivedStateFromProps() method is used when the state of a component depends on changes of props. getDerivedStateFromProps(props ...
Read more >
How to use componentDidUpdate in React
componentDidUpdate() is called after componentDidMount() and can be useful to perform some action when the state changes. componentDidUpdate() ...
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