fix(lint): resolve react-hooks/set-state-in-effect in storage and suggestions clients

This commit is contained in:
2026-05-10 02:02:01 +08:00
parent c9adf80d88
commit f02408c0c7
2 changed files with 19 additions and 19 deletions
@@ -101,7 +101,6 @@ export function StorageClient() {
const isSearchChangeRef = useRef(false) const isSearchChangeRef = useRef(false)
useEffect(() => { useEffect(() => {
setStatsLoading(true)
fetch("/api/admin/storage/stats") fetch("/api/admin/storage/stats")
.then((res) => res.json()) .then((res) => res.json())
.then((data) => { .then((data) => {
@@ -1,6 +1,6 @@
"use client" "use client"
import { useCallback, useEffect, useMemo, useState } from "react" import { useEffect, useMemo, useState } from "react"
import Link from "next/link" import Link from "next/link"
import { cn } from "@/lib/utils" import { cn } from "@/lib/utils"
import { ConfirmDialog } from "@/components/ui/modal" import { ConfirmDialog } from "@/components/ui/modal"
@@ -65,25 +65,26 @@ export function SuggestionsClient() {
{ label: "Rejected", value: "rejected" }, { label: "Rejected", value: "rejected" },
] ]
const fetchSuggestions = useCallback(async () => { useEffect(() => {
setLoading(true) let cancelled = false
const run = async () => {
try { try {
const res = await fetch(`/api/community-suggestions/admin?limit=${LIMIT}`) const res = await fetch(`/api/community-suggestions/admin?limit=${LIMIT}`)
if (res.ok) { if (res.ok && !cancelled) {
const json = (await res.json()) as SuggestionsApiResponse const json = (await res.json()) as SuggestionsApiResponse
setSuggestions(json.data) setSuggestions(json.data)
setTotal(json.total) setTotal(json.total)
} }
setOffset(0) } catch {
// ignore
} finally { } finally {
setLoading(false) if (!cancelled) setLoading(false)
} }
}
run()
return () => { cancelled = true }
}, []) }, [])
useEffect(() => {
fetchSuggestions()
}, [fetchSuggestions])
const filtered = useMemo(() => { const filtered = useMemo(() => {
let result = suggestions let result = suggestions
const term = search.trim().toLowerCase() const term = search.trim().toLowerCase()