我正在使用React-router-dom开发一个React 应用程序。
我有一个带有一些 react-router-dom 的菜单<NavLink />
,每个菜单都带我到不同的路线。
在我的主要途径path="/"
我有chartComponent与上用随机数据发生变化,这样保持一个图表:this.chartChangeId = setInterval(()=> this.setState(data), 1500)
。
在我添加这个之前:
componentWillUnmount(){
clearInterval(this.chartChangeId);
}
到chartComponent我的应用程序没有中断,但我收到了这个错误:
警告:只能更新已安装或正在安装的组件。这通常意味着您在未安装的组件上调用了 setState、replaceState 或 forceUpdate。这是一个无操作。请检查 BrainWaveChart 组件的代码。
所以我把它添加到生命周期中。
但是现在,当我单击其中一个<NavLink />
转到另一条路线时,我的应用程序中断了,并且出现此错误:
未捕获的类型错误:timeout.close 不是一个函数 atexports.clearTimeout.exports.clearInterval (main.js:14) at BrainWaveChart.componentWillUnmount (brainwaveChart.jsx:116) at callComponentWillUnmountWithTimer (vendor_f02cab182c1842c94callCallback(HTML) (HTML): vendor_f02cab182c1842c98837.js:37015)在Object.invokeGuardedCallbackDev(vendor_f02cab182c1842c98837.js:37054)在invokeGuardedCallback(vendor_f02cab182c1842c98837.js:36911)在safelyCallComponentWillUnmount(vendor_f02cab182c1842c98837.js:45242)在commitUnmount(vendor_f02cab182c1842c98837.js:45368)在commitNestedUnmounts(vendor_f02cab182c1842c98837.js :45404) 在 unmountHostComponents (vendor_f02cab182c1842c98837.js:45687)
我做错了吗?