Skip to content

Commit 22229e8

Browse files
Ajit Pratap Singhclaude
authored andcommitted
fix(playground): move useState/useCallback above early returns to fix React error #310
useState(copied) and useCallback(handleCopy) were declared after the if (loading) and if (error) early returns, violating the Rules of Hooks. When the WASM binary was a 404, the component always hit the error branch so both renders exited with the same hook count. After committing the WASM binary (#423), the component now successfully transitions loading→ready, causing React to see 11 hooks instead of 9 on the second render → #310. Fix: move both hooks above all conditional returns. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
1 parent 162ac85 commit 22229e8

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)