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.

ArrowKeyStepper: setState(...) in `componentWillUpdate`

See original GitHub issue

Hi, not sure if this should be considered an issue, but I thought it would not hurt to talk about it. In the ArrowKeyStepper component, into the componentWillUpdate React lifecycle method, there is a call to setState(…). I am not entirely sure that’s correct. (https://facebook.github.io/react/docs/react-component.html#componentwillupdate). Isn’t it a best practice to use componentWillReceiveProps instead?

Also, I see that the state is updated if the new set of props differ from the old set of props. But this way, if the component updates its state as a result of key down events and then it receives a new pair of values for scrollToRow and scrollToIndex from a parent component (say, for example, as the result of clicking on one of the items of the wrapped List or Grid), those values will not end up in the state, and the component will not be able to reflect those in its render method. (if not clear, I’ll try to come up with a small demo).

Thoughts?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
bvaughncommented, Feb 22, 2017

Not sure how I could access an instance of the element in order to call this method.

With a ref 😄

class MyComponent extends Component {
  render () {
    return (
      <ArrowKeyStepper
        {...this.props}
        ref={this._setRef}
      />
    )
  }

  _setRef (ref) {
    // If you later need to use any public methods
    // You can: this._arrowKeyStepperRef.somePublicMethod()
    this._arrowKeyStepperRef = ref
  }
}

Were you thinking to expose such a method in as an additional property in the children(…) function?

We could potentially do that as well.

0reactions
bvaughncommented, Feb 25, 2017

Resolved by #592

Read more comments on GitHub >

github_iconTop Results From Across the Web

reactjs - componentWillUpdate infinite loop when setState
in componentDidUpdate ,never use setState,every time when it changes state which would be continuous ,it will go in infinite loop.
Read more >
react-virtualized | Yarn - Package Manager
React components for efficiently rendering large lists and tabular data. Check out the demo for some examples. Sponsors. The following wonderful companies ...
Read more >
Hi! You can call setState in the lifecycle methods ... - Medium
Hi! You can call setState in the lifecycle methods componentWillUpdate and componentDidUpdate. To prevent the infinite loop you need to add ...
Read more >
ba-ui-toolkit.min.js.map - IBM Cognos Analytics
node_modules/react-virtualized/dist/es/ArrowKeyStepper/ArrowKeyStepper.js","webpack:///./node_modules/core-js/library/modules/_uid.js","webpack:///.
Read more >
https://ia.gov.ae/Style%20Library/IA_Branding/js/c...
node_modules/dom-css/index.js","../node_modules/react-virtualized/dist/es/ArrowKeyStepper/ArrowKeyStepper.js",".
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