setState can only update a mounted component warning
I'm getting the following warning in the console
Here's the Snippet component causing the warning. I'm setting state in componentDidMount.
I tried making a jsfiddle but there's too many dependencies. The error logged will increment on resize but it doesn't always happen.
Could be because checkClearFix is being called when a resize occurs and the component is not mounted in the DOM?
Hmm I just thought of that and removed it on componentWillUnmount
componentWillUnmount() {
if (!this.props.splitTheGrid) {
window.removeEventListener('resize', false)
}
}
but it's still happening
@timurtu you have to pass the listener to removeEventListener, just like you do with addEventListener. You should just bind checkClearFix in the constructor and pass it directly to addEventListener instead of wrapping it in an arrow function that just calls it. Then you could pass this.checkClearFix to both addEventListener and removeEventListener
Oh okay. Like this? It now says setState is not a function.
I also tried binding it here and now it gives the error from before

You would need to set the bind: this.checkClearFix = this.checkClearFix.bind(this);.
that worked ty