|
1 | 1 | /* eslint-disable react-hooks/exhaustive-deps */ |
2 | 2 | /* eslint-disable react/display-name */ |
3 | 3 |
|
4 | | -import React, { useEffect, useState, useRef } from 'react'; |
| 4 | +import React, { useEffect, useState, useRef, useMemo } from 'react'; |
5 | 5 | import debounce from 'lodash.debounce'; |
6 | 6 | import { assertNotNull } from '@deephaven/utils'; |
7 | 7 | import './RandomAreaPlotAnimation.scss'; |
@@ -42,14 +42,9 @@ function getRandomAreaPlotAnimationThemeColors(): ThemeColors { |
42 | 42 | const RandomAreaPlotAnimation = React.memo(() => { |
43 | 43 | const { activeThemes } = useTheme(); |
44 | 44 |
|
45 | | - const [themeColors, setThemeColors] = useState<ThemeColors | null>(null); |
46 | | - |
47 | | - // Resolving css variables has to run in `useEffect` or `useLayoutEffect` so |
48 | | - // that we know React has updated the DOM with any styles set by the |
49 | | - // ThemeProvider. |
50 | | - useEffect(() => { |
51 | | - setThemeColors(getRandomAreaPlotAnimationThemeColors()); |
52 | | - }, [activeThemes]); |
| 45 | + const themeColors = useMemo(getRandomAreaPlotAnimationThemeColors, [ |
| 46 | + activeThemes, |
| 47 | + ]); |
53 | 48 |
|
54 | 49 | const canvas = useRef<HTMLCanvasElement>(null); |
55 | 50 | const container = useRef<HTMLDivElement>(null); |
@@ -85,10 +80,6 @@ const RandomAreaPlotAnimation = React.memo(() => { |
85 | 80 |
|
86 | 81 | // Returns the background fill create offscreen as pattern |
87 | 82 | function createPatternFill(): CanvasPattern | null | undefined { |
88 | | - if (themeColors == null) { |
89 | | - return null; |
90 | | - } |
91 | | - |
92 | 83 | const { foregroundFill, foregroundStroke } = themeColors; |
93 | 84 |
|
94 | 85 | // create the off-screen canvas |
@@ -189,10 +180,6 @@ const RandomAreaPlotAnimation = React.memo(() => { |
189 | 180 | * @param timestamp passed in callback from requestAnimationFrame |
190 | 181 | */ |
191 | 182 | function drawCanvas(timestamp?: DOMHighResTimeStamp): void { |
192 | | - if (themeColors == null) { |
193 | | - return; |
194 | | - } |
195 | | - |
196 | 183 | lastTimestamp = lastTimestamp ?? timestamp; |
197 | 184 |
|
198 | 185 | const { background, foregroundStroke, gridColor } = themeColors; |
@@ -343,11 +330,9 @@ const RandomAreaPlotAnimation = React.memo(() => { |
343 | 330 | }, [themeColors]); |
344 | 331 |
|
345 | 332 | return ( |
346 | | - themeColors && ( |
347 | | - <div className="random-area-plot-animation-container" ref={container}> |
348 | | - <canvas ref={canvas} className={shade ? 'shade' : ''} /> |
349 | | - </div> |
350 | | - ) |
| 333 | + <div className="random-area-plot-animation-container" ref={container}> |
| 334 | + <canvas ref={canvas} className={shade ? 'shade' : ''} /> |
| 335 | + </div> |
351 | 336 | ); |
352 | 337 | }); |
353 | 338 |
|
|
0 commit comments