Skip to content

Commit 1e6845b

Browse files
committed
Checking form result in useEffect callback
FIXED: I moved to the useEffect callback, it was work well.
1 parent a772ba3 commit 1e6845b

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

src/app/app.tsx

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,23 @@ export default function App({ optOutUrl }: OptOutUrl) {
3838
const handleSubmit = async (e: SubmitEvent) => {
3939
e.preventDefault()
4040
dispatch(submitCreator(e.target))
41-
if (result === Result.invalid || result === Result.blocked) return
42-
4341
if (isKeepLogin) saveAccountInfo(getElementValues(e.target))
42+
}
43+
44+
useEffect(() => {
45+
setKeepLogin(isKeepLogin)
46+
submitWhenKeepLogin()
47+
}, [isKeepLogin])
48+
49+
useEffect(() => {
50+
if (
51+
result === Result.idle ||
52+
result === Result.invalid ||
53+
result === Result.blocked
54+
) {
55+
// prettier-ignore
56+
return
57+
}
4458

4559
if (result === Result.correct) {
4660
location.href = 'main.do'
@@ -52,13 +66,10 @@ export default function App({ optOutUrl }: OptOutUrl) {
5266
return
5367
}
5468

55-
throw Error('Unexpect state flow in handleSubmit')
56-
}
57-
58-
useEffect(() => {
59-
setKeepLogin(isKeepLogin)
60-
submitWhenKeepLogin()
61-
}, [isKeepLogin])
69+
throw Error(
70+
`Unexpect result flow in handleSubmit' current value: ${Result[result]}`
71+
)
72+
}, [result])
6273

6374
const onChange = () => {
6475
if (isWrong) dispatch(IDLE)

0 commit comments

Comments
 (0)