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.

Unable to disable the react/no-did-mount-set-state check

See original GitHub issue

I have the following code:

    const elementHeight = isNaN(this.trElement.clientHeight) ? 0 : this.trElement.clientHeight;
    const elementWidth = isNaN(this.trElement.clientWidth) ? 0 : this.trElement.clientWidth;
    const firstItem = this.firstItem || this.parenNameEle;
    const firstItemWidth = isNaN(firstItem.clientWidth) ? 0 : firstItem.clientWidth;
    this.setState({ elementWidth, elementHeight, firstItemWidth });
  }

When I run the eslint-plugin-react over this code I get the following error:

71:5  error  Do not use setState in componentDidMount  react/no-did-mount-set-state

That is working as expected. If I then add this line right before calling this.setState the error goes away:

/* eslint-disable react/no-did-mount-set-state */

However, I am unable to disable this rule in my .eslintrc file. When I try the following:

"rules": {
    "react/no-did-mount-set-state": 0,

The error still happens when I run eslint. I would expect adding this to my .eslintrc file would stop that check.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
zgrossbartcommented, Mar 9, 2018

Groan. You were totally right. I had a bunch of then in my node_modules files so I didn’t see that there was one in the src directory. When I change it there it works. I feel more than a little silly now. Thank you very much for all of your help and time.

0reactions
ljharbcommented, Mar 9, 2018

I’m asking if there could be other eslint config files (theres multiple supported file names) that are affecting the settings.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to disable the react/no-did-mount-set-state check #1711
I have the following code: const elementHeight = isNaN(this.trElement.clientHeight) ? 0 : this.trElement.clientHeight; const elementWidth ...
Read more >
Can't perform a React state update on an unmounted ...
I am writing an application in React and was unable to avoid a super common pitfall, which is calling setState(...) after componentWillUnmount(.
Read more >
React: Stop checking if your component is mounted - Medium
This article will provide solutions to the “Can't perform a React state update on an unmounted component” warning and why a call to...
Read more >
Prevent React setState on unmounted Component
How to avoid the React warning: Can only update a mounted or mounting component. It usually means you have called setState on an...
Read more >
Optimizing Performance - React
For a more detailed walkthrough, check out this article by Ben Schwarz. ... returned false for the subtree rooted at C2, React did...
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