mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
fix(plugin-chart-echarts): layout broken when resizing (#20783)
* fix(plugin-chart-echarts): layout broken when resizing * use useLayoutEffect
This commit is contained in:
@@ -22,6 +22,8 @@ import React, {
|
||||
useMemo,
|
||||
forwardRef,
|
||||
useImperativeHandle,
|
||||
useLayoutEffect,
|
||||
useCallback,
|
||||
} from 'react';
|
||||
import { styled } from '@superset-ui/core';
|
||||
import { ECharts, init } from 'echarts';
|
||||
@@ -92,11 +94,23 @@ function Echart(
|
||||
previousSelection.current = currentSelection;
|
||||
}, [currentSelection]);
|
||||
|
||||
const handleSizeChange = useCallback(
|
||||
({ width, height }: { width: number; height: number }) => {
|
||||
if (chartRef.current) {
|
||||
chartRef.current.resize({ width, height });
|
||||
}
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
// did mount
|
||||
useEffect(() => {
|
||||
if (chartRef.current) {
|
||||
chartRef.current.resize({ width, height });
|
||||
}
|
||||
}, [width, height]);
|
||||
handleSizeChange({ width, height });
|
||||
}, []);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
handleSizeChange({ width, height });
|
||||
}, [width, height, handleSizeChange]);
|
||||
|
||||
return <Styles ref={divRef} height={height} width={width} />;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user