Skip to content

Commit 68fa4d3

Browse files
committed
fix(compare-form): accept username state as props
The PR call site lifted username1/username2 and their setters into HomePageInner so URL searchParams could drive the form, but the component itself still owned its own useState pair. That broke the build and meant the prop-passed values were ignored at runtime. Move the four values into CompareFormProps, drop the internal useState, and let parent-supplied swapUsers/reset handle clearing and swapping. The local placeholder defaults ("pbiggar", "CoralineAda") are gone; the parent now seeds initial state from searchParams.
1 parent 09d5da7 commit 68fa4d3

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

components/compare-form.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState, useRef, useEffect } from "react";
1+
import { useRef, useEffect } from "react";
22
import { Button } from "./ui/button";
33
import { ArrowLeftRight, RefreshCw } from "lucide-react";
44
import {
@@ -12,6 +12,10 @@ import { Alert, AlertDescription } from "./ui/alert";
1212
import { useTranslation } from "./language-provider";
1313

1414
type CompareFormProps = {
15+
username1: string;
16+
username2: string;
17+
setUsername1: (value: string) => void;
18+
setUsername2: (value: string) => void;
1519
data?: boolean;
1620
onSubmit: (u1: string, u2: string) => void;
1721
loading?: boolean;
@@ -21,16 +25,17 @@ type CompareFormProps = {
2125
};
2226

2327
export function CompareForm({
28+
username1,
29+
username2,
30+
setUsername1,
31+
setUsername2,
2432
onSubmit,
25-
data,
2633
loading,
2734
swapUsers,
2835
reset,
2936
error,
3037
}: CompareFormProps) {
3138
const { t } = useTranslation();
32-
const [username1, setUsername1] = useState("pbiggar");
33-
const [username2, setUsername2] = useState("CoralineAda");
3439
const firstInputRef = useRef<HTMLInputElement>(null);
3540

3641
// Auto-focus first input on page load
@@ -42,14 +47,10 @@ export function CompareForm({
4247
const isEmpty = !username1.trim() && !username2.trim();
4348

4449
const handleSwap = () => {
45-
setUsername1(username2);
46-
setUsername2(username1);
4750
if (swapUsers) swapUsers();
4851
};
4952

5053
const handleReset = () => {
51-
setUsername1("");
52-
setUsername2("");
5354
if (reset) reset();
5455
};
5556

0 commit comments

Comments
 (0)