Skip to content

Commit

Permalink
Checking form result in useEffect callback
Browse files Browse the repository at this point in the history
FIXED: I moved to the useEffect callback, it was work well.
  • Loading branch information
mu-hun committed Aug 9, 2020
1 parent a772ba3 commit 1e6845b
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,23 @@ export default function App({ optOutUrl }: OptOutUrl) {
const handleSubmit = async (e: SubmitEvent) => {
e.preventDefault()
dispatch(submitCreator(e.target))
if (result === Result.invalid || result === Result.blocked) return

if (isKeepLogin) saveAccountInfo(getElementValues(e.target))
}

useEffect(() => {
setKeepLogin(isKeepLogin)
submitWhenKeepLogin()
}, [isKeepLogin])

useEffect(() => {
if (
result === Result.idle ||
result === Result.invalid ||
result === Result.blocked
) {
// prettier-ignore
return
}

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

throw Error('Unexpect state flow in handleSubmit')
}

useEffect(() => {
setKeepLogin(isKeepLogin)
submitWhenKeepLogin()
}, [isKeepLogin])
throw Error(
`Unexpect result flow in handleSubmit' current value: ${Result[result]}`
)
}, [result])

const onChange = () => {
if (isWrong) dispatch(IDLE)
Expand Down

0 comments on commit 1e6845b

Please sign in to comment.