Skip to content

Commit cec5acc

Browse files
authored
fix(playground): move useState/useCallback above early returns to fix React error #310 (#429)
Hooks (useState for copied, useCallback for handleCopy) were placed after conditional early returns for loading/error states, violating React Rules of Hooks. Moved both hooks above the early returns so all 11 hooks are called unconditionally on every render. Root cause: the hooks violation was previously masked because the WASM binary was missing (404), so the component always stayed in the error branch. Once the WASM binary was committed (#423), the loading→ready transition exposed the hook count mismatch, triggering React error #310. Fixes #427
1 parent 9562968 commit cec5acc

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

website/src/components/playground/Playground.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,15 @@ export default function Playground() {
109109
[]
110110
);
111111

112+
const [copied, setCopied] = useState(false);
113+
114+
const handleCopy = useCallback(() => {
115+
navigator.clipboard.writeText('go get github.com/ajitpratap0/GoSQLX').then(() => {
116+
setCopied(true);
117+
setTimeout(() => setCopied(false), 2000);
118+
});
119+
}, []);
120+
112121
if (loading) {
113122
return (
114123
<div className="flex flex-col h-full bg-[#09090b]" aria-busy="true" aria-label="Loading SQL parser">
@@ -190,16 +199,8 @@ export default function Playground() {
190199
);
191200
}
192201

193-
const [copied, setCopied] = useState(false);
194202
const hasResults = results.ast !== null;
195203

196-
const handleCopy = useCallback(() => {
197-
navigator.clipboard.writeText('go get github.com/ajitpratap0/GoSQLX').then(() => {
198-
setCopied(true);
199-
setTimeout(() => setCopied(false), 2000);
200-
});
201-
}, []);
202-
203204
return (
204205
<div className="flex flex-col h-full bg-[#09090b]">
205206
{/* Top toolbar */}

0 commit comments

Comments
 (0)