diff --git a/src/components/Display.jsx b/src/components/Display.jsx index 763b634..e39a9b7 100644 --- a/src/components/Display.jsx +++ b/src/components/Display.jsx @@ -1,11 +1,10 @@ -import { useState, useEffect } from 'react'; +import { useState, useEffect, useRef } from 'react'; import {CaretUpOutlined, CaretDownOutlined} from '@ant-design/icons' export const ValueDisplay = ({prefix, value, suffix, isArrowVisible}) =>{ const [oldVal, setOldVal] = useState(NaN) const [val, setVal] = useState('---') - - let arrow = null + const arrowRef = useRef(null); useEffect(()=>{ if(value) @@ -14,16 +13,16 @@ export const ValueDisplay = ({prefix, value, suffix, isArrowVisible}) =>{ if (isArrowVisible) { if (value > oldVal) - arrow = + arrowRef.current = () else if (value < oldVal) - arrow = + arrowRef.current = () setOldVal(value) } } else setVal(value) },[value]) - return({prefix} {val} {suffix}{arrow}) + return({prefix} {val} {suffix}{arrowRef.current}) } export const Display = (props)=>{