diff --git a/packages/frontend/src/components/charts/index.js b/packages/frontend/src/components/charts/index.js index cd80d17f3..18e996347 100644 --- a/packages/frontend/src/components/charts/index.js +++ b/packages/frontend/src/components/charts/index.js @@ -28,43 +28,26 @@ const LineChart = ({ data, timespan, xAxis = { title: '', type: { axis: 'number' const render = useCallback(() => { if (!chartContainer.current) return - setLoading(true) setChartElement('') + setLoading(!loading) + }, [loading]) - let lastWidth = chartContainer.current.offsetWidth - - const setupChart = () => { - setTimeout(() => { - if (!chartContainer.current) { - setLoading(false) - return - } - - if (chartContainer.current.offsetWidth !== lastWidth) { - lastWidth = chartContainer.current.offsetWidth - setupChart() - return - } - - setChartElement() - - setLoading(false) - }, 100) - } - - setupChart() - }, [data, timespan, xAxis, yAxis]) + useEffect(() => { + if (chartElement !== '') return + + setChartElement() + }, [chartElement, loading, data, timespan, xAxis, yAxis]) useResizeObserver(chartContainer.current, render) - useEffect(render, [data, render, data, timespan, xAxis, yAxis, loading]) + useEffect(() => render, [data, render]) return