Fix unused tick state causing TS build error in CpuChart
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { useEffect, useRef, useState } from "react"
|
import { useEffect, useRef } from "react"
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
|
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
@@ -32,17 +32,13 @@ function loadColor(load: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function CpuChart({ history, loadAvg }: CpuChartProps) {
|
export function CpuChart({ history, loadAvg }: CpuChartProps) {
|
||||||
const [tick, setTick] = useState(0)
|
|
||||||
const prevLenRef = useRef(0)
|
const prevLenRef = useRef(0)
|
||||||
const currentCpu = history.length > 0 ? history[history.length - 1].cpuPercent : 0
|
const currentCpu = history.length > 0 ? history[history.length - 1].cpuPercent : 0
|
||||||
const color = cpuColor(currentCpu)
|
const color = cpuColor(currentCpu)
|
||||||
|
|
||||||
// Trigger CSS transition whenever a new point arrives
|
// Track history length changes (used to drive CSS transitions via key changes)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (history.length !== prevLenRef.current) {
|
prevLenRef.current = history.length
|
||||||
prevLenRef.current = history.length
|
|
||||||
setTick(t => t + 1)
|
|
||||||
}
|
|
||||||
}, [history.length])
|
}, [history.length])
|
||||||
|
|
||||||
// Assign fixed x positions: latest point always at right edge, older ones to the left
|
// Assign fixed x positions: latest point always at right edge, older ones to the left
|
||||||
|
|||||||
Reference in New Issue
Block a user