eslint-plugin-react: Unable to disable the react/no-did-mount-set-state check
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.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 16 (8 by maintainers)
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.