From 348c62847d2f185c09f9b9d130ada743e3600b9b Mon Sep 17 00:00:00 2001 From: afc163 Date: Thu, 16 May 2019 17:31:49 +0800 Subject: [PATCH] Fix setState after unmount --- src/components/Charts/Pie/index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/Charts/Pie/index.js b/src/components/Charts/Pie/index.js index 5f80d747..c6370ea3 100644 --- a/src/components/Charts/Pie/index.js +++ b/src/components/Charts/Pie/index.js @@ -41,6 +41,9 @@ class Pie extends Component { window.cancelAnimationFrame(this.requestRef); window.removeEventListener('resize', this.resize); this.resize.cancel(); + if (this.chartDom) { + this.resizeObserverInstance.unobserve(this.chartDom); + } } getG2Instance = chart => { @@ -94,7 +97,7 @@ class Pie extends Component { }; resizeObserver() { - const ro = new ResizeObserver(entries => { + this.resizeObserverInstance = new ResizeObserver(entries => { const { height } = entries[0].contentRect; this.setState(preState => { if (preState.height !== height) { @@ -106,7 +109,7 @@ class Pie extends Component { }); }); if (this.chartDom) { - ro.observe(this.chartDom); + this.resizeObserverInstance.observe(this.chartDom); } } -- GitLab