Skip to content

Commit 448d787

Browse files
committed
Switch to ref.
1 parent 84a12c0 commit 448d787

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

frontend/src/pages/Settings/Login.tsx

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,25 @@ import {
1616
} from "@ionic/react"
1717
import { useHistory } from "react-router"
1818
import { useQueryClient } from "@tanstack/react-query"
19-
import { useState } from "react"
19+
import { useRef } from "react"
2020
import { useAuth } from "@/hooks"
2121
import { InfoBanners } from "@/components"
2222

2323
const SettingsLoginPage: React.FC = () => {
2424
const queryClient = useQueryClient()
2525
const history = useHistory()
2626
const [{ username, token }, saveAuth] = useAuth()
27-
const [newUsername, setNewUsername] = useState<string>(username ?? "")
28-
const [newPassword, setNewPassword] = useState<string>(token ?? "")
2927
const ionConfig = getConfig()
3028
const currentMode = ionConfig?.get("mode") || "ios"
3129

30+
const usernameInputRef = useRef<HTMLIonInputElement>(null)
31+
const passwordInputRef = useRef<HTMLIonInputElement>(null)
32+
3233
const handleSave = () => {
33-
saveAuth(newUsername, newPassword)
34+
const newUsername = (usernameInputRef.current?.value as string) || username
35+
const newPassword = (passwordInputRef.current?.value as string) || token
36+
37+
saveAuth(newUsername ?? "", newPassword ?? "")
3438
queryClient.clear()
3539
history.push("/")
3640
window.location.reload()
@@ -57,19 +61,10 @@ const SettingsLoginPage: React.FC = () => {
5761
<IonContent className="ion-padding">
5862
<IonList inset={true}>
5963
<IonItem color={lightMode}>
60-
<IonInput
61-
label="Username"
62-
value={newUsername}
63-
onIonChange={(e) => setNewUsername(`${e.target.value}`)}
64-
/>
64+
<IonInput label="Username" value={username} ref={usernameInputRef} />
6565
</IonItem>
6666
<IonItem color={lightMode}>
67-
<IonInput
68-
type="password"
69-
label="Token"
70-
value={newPassword}
71-
onIonChange={(e) => setNewPassword(`${e.target.value}`)}
72-
>
67+
<IonInput type="password" label="Token" value={token} ref={passwordInputRef}>
7368
<IonInputPasswordToggle slot="end" />
7469
</IonInput>
7570
</IonItem>

0 commit comments

Comments
 (0)