fix(tests): move showTemplateModal useState before early returns (React #310)
Some checks failed
Aegis CI / lint-and-test (push) Has been cancelled

The useState hook was placed after the isLoading/error early returns,
violating the Rules of Hooks. First render hit the early return without
calling the hook; second render (after data loaded) called it, producing
'more hooks than previous render' — React error #310 and a white screen.

Moved const [showTemplateModal] to the state block at the top of the
component, alongside the other useState declarations.
This commit is contained in:
kitos
2026-05-29 13:29:17 +02:00
parent 6c8a1317fd
commit 70b5c833d4

View File

@@ -65,6 +65,7 @@ export default function TestDetailPage() {
}); });
const [toast, setToast] = useState<{ message: string; type: "success" | "error" } | null>(null); const [toast, setToast] = useState<{ message: string; type: "success" | "error" } | null>(null);
const [showTemplateModal, setShowTemplateModal] = useState(false);
// ── Queries ──────────────────────────────────────────────────── // ── Queries ────────────────────────────────────────────────────
@@ -366,8 +367,6 @@ export default function TestDetailPage() {
const canSaveAsTemplate = const canSaveAsTemplate =
role === "red_lead" || role === "blue_lead" || role === "admin"; role === "red_lead" || role === "blue_lead" || role === "admin";
const [showTemplateModal, setShowTemplateModal] = useState(false);
// ── Render ───────────────────────────────────────────────────── // ── Render ─────────────────────────────────────────────────────
return ( return (