Skip to content

Commit

Permalink
fix: errors get reset on each submit
Browse files Browse the repository at this point in the history
  • Loading branch information
iremlopsum committed Apr 26, 2022
1 parent 07c2916 commit bdac385
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,19 @@ export default function useForm<K extends Form>(
const onHandleSubmit = (): void => {
const valueKeys = Object.keys(state)
const validator = formValidation

setErrors(
(function (): { [key in keyof K]: false | string } {
let errs = formSchema

for (const [key] of Object.entries(formSchema)) {
errs = { ...errs, [key]: false }
}

return errs
})(),
)

let currentErrors = errors

const errorsArray = valueKeys.map((key) => {
Expand Down

0 comments on commit bdac385

Please sign in to comment.