fix(tests): move showTemplateModal useState before early returns (React #310)
Some checks failed
Aegis CI / lint-and-test (push) Has been cancelled
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:
@@ -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 (
|
||||||
|
|||||||
Reference in New Issue
Block a user