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:
2026-03-23 16:47:57 +05:30
parent 201d40c481
commit a22f7b535a

View File

@@ -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