I'm working on a React app with React-router-dom.
I have a menu with some react-router-dom's <NavLink />
, each one takes me to a different route.
In my main route path="/"
I have chartComponent with a chart that keeps on changing with random data, like this: this.chartChangeId = setInterval(()=> this.setState(data), 1500)
.
before I added this:
componentWillUnmount(){
clearInterval(this.chartChangeId);
}
To chartComponent my app didn't break, but I got this error:
Warning: Can only update a mounted or mounting component. This usually means you called setState, replaceState, or forceUpdate on an unmounted component. This is a no-op. Please check the code for the BrainWaveChart component.
so I added this to the life cycle.
But now, when I click on one of the <NavLink />
to go to a different route my app breaks, and I get this error:
Uncaught TypeError: timeout.close is not a function at exports.clearTimeout.exports.clearInterval (main.js:14) at BrainWaveChart.componentWillUnmount (brainwaveChart.jsx:116) at callComponentWillUnmountWithTimer (vendor_f02cab182c1842c98837.js:45235) at HTMLUnknownElement.callCallback (vendor_f02cab182c1842c98837.js:37015) at Object.invokeGuardedCallbackDev (vendor_f02cab182c1842c98837.js:37054) at invokeGuardedCallback (vendor_f02cab182c1842c98837.js:36911) at safelyCallComponentWillUnmount (vendor_f02cab182c1842c98837.js:45242) at commitUnmount (vendor_f02cab182c1842c98837.js:45368) at commitNestedUnmounts (vendor_f02cab182c1842c98837.js:45404) at unmountHostComponents (vendor_f02cab182c1842c98837.js:45687)
Am I doing it wrong ?