refactor(react-hooks): enable stricter effect rules

Turn on react-hooks/set-state-in-effect and react-hooks/incompatible-library, then remove effect-driven local state sync patterns across affected pages. Keep behavior stable by deriving values from source state, remounting tab state by role key, and replacing useForm watch with useWatch.
This commit is contained in:
zetaloop
2026-02-22 10:03:00 +08:00
parent c9dbf5037e
commit 519fb92c34
9 changed files with 36 additions and 59 deletions
@@ -5,7 +5,7 @@ import { ArrowLeft } from "lucide-react"
import Link from "next/link"
import { useRouter, useSearchParams } from "next/navigation"
import { useEffect } from "react"
import { useForm } from "react-hook-form"
import { useForm, useWatch } from "react-hook-form"
import { z } from "zod"
import { Button } from "@/components/ui/button"
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
@@ -48,7 +48,7 @@ export default function NewServicePage() {
register,
handleSubmit,
setValue,
watch,
control,
formState: { errors, isSubmitting },
} = useForm<z.infer<typeof serviceSchema>>({
resolver: standardSchemaResolver(serviceSchema),
@@ -74,8 +74,8 @@ export default function NewServicePage() {
setValue("availability", editingService.availability.join("、"))
}, [editingService, setValue])
const selectedGameId = watch("gameId")
const selectedUnit = watch("unit")
const selectedGameId = useWatch({ control, name: "gameId" })
const selectedUnit = useWatch({ control, name: "unit" })
const games = listGames()
const onSubmit = async (data: z.infer<typeof serviceSchema>) => {
@@ -51,10 +51,6 @@ export default function ShopTemplatesPage() {
}
}, [showSavedToast])
useEffect(() => {
setSections([...shop.templateConfig.sections].sort((a, b) => a.order - b.order))
}, [shop])
const toggleSection = (type: ShopSection["type"]) => {
setSections((prev) => prev.map((s) => (s.type === type ? { ...s, enabled: !s.enabled } : s)))
}