forked from ddrilling/asb_cloud_front
CF2-7: Fix с добавлением useState
This commit is contained in:
parent
a05122305f
commit
47262a8b8f
@ -1,23 +1,27 @@
|
|||||||
import { useState } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
import {CaretUpOutlined, CaretDownOutlined} from '@ant-design/icons'
|
import {CaretUpOutlined, CaretDownOutlined} from '@ant-design/icons'
|
||||||
|
|
||||||
export const ValueDisplay = ({prefix, value, suffix, isArrowVisible}) =>{
|
export const ValueDisplay = ({prefix, value, suffix, isArrowVisible}) =>{
|
||||||
const [oldVal, setOldVal] = useState(NaN)
|
const [oldVal, setOldVal] = useState(NaN)
|
||||||
|
const [val, setVal] = useState('---')
|
||||||
|
|
||||||
let val = '---'
|
|
||||||
let arrow = null
|
let arrow = null
|
||||||
|
|
||||||
|
useEffect(()=>{
|
||||||
if(value)
|
if(value)
|
||||||
if(Number.isFinite(+value)){
|
if(Number.isFinite(+value)){
|
||||||
val = (+value).toPrecision(4)??'---'
|
setVal((+value).toPrecision(4)??'---')
|
||||||
if (isArrowVisible)
|
if (isArrowVisible)
|
||||||
{
|
{
|
||||||
arrow = value > oldVal
|
if (value > oldVal)
|
||||||
? <CaretUpOutlined style={{color:"red"}} onClick={!isArrowVisible} />
|
arrow = <CaretUpOutlined style={{color:"red"}} />
|
||||||
: <CaretDownOutlined style={{color:"red"}} onClick={!isArrowVisible} />
|
else if (value < oldVal)
|
||||||
|
arrow = <CaretDownOutlined style={{color:"red"}} />
|
||||||
setOldVal(value)
|
setOldVal(value)
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
val = value
|
setVal(value)
|
||||||
|
},[value])
|
||||||
|
|
||||||
return(<span className='display_value'>{prefix} {val} {suffix}{arrow}</span>)
|
return(<span className='display_value'>{prefix} {val} {suffix}{arrow}</span>)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user