From 724e48f73853f4e70bf28575f36bb1031f2c1fde Mon Sep 17 00:00:00 2001 From: gluap Date: Sun, 19 Dec 2021 17:01:13 +0100 Subject: [PATCH] Implement requested change to native react idiom --- frontend/src/components/ColorMapLegend.tsx | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/frontend/src/components/ColorMapLegend.tsx b/frontend/src/components/ColorMapLegend.tsx index b5c615a..af97691 100644 --- a/frontend/src/components/ColorMapLegend.tsx +++ b/frontend/src/components/ColorMapLegend.tsx @@ -1,3 +1,5 @@ +import {useMemo} from "react"; + type ColorMap = [number, string][] import styles from './ColorMapLegend.module.less' @@ -6,24 +8,20 @@ export default function ColorMapLegend({map}: {map: ColorMap}) { const min = map[0][0] const max = map[map.length - 1][0] const normalizeValue = (v) => (v - min) / (max - min) - if( typeof ColorMapLegend.counter == 'undefined' ) { - ColorMapLegend.counter = 0; - } - ColorMapLegend.counter++; - ColorMapLegend.id="gradient"+ColorMapLegend.counter; - ColorMapLegend.url="url(#"+ColorMapLegend.id+")"; + const gradientId = useMemo(() => `gradient${Math.floor(Math.random() * 1000000)}`, []); + const gradientUrl = `url(#${gradientId})`; return (
- + {map.map(([value, color]) => ( ))} - + {map.map(([value]) => (