New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix/improve setError & clearError #1907
Conversation
Size Change: -597 B (0%) Total Size: 70.5 kB
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit b09faa9:
|
I think we could go back to this and |
Totally agree, otherwise the API name is very confusing against its functionality.
if users complains about the multiple re-render, we can then consider introducing setValues setErrors, ideally to avoid. |
src/types/form.ts
Outdated
types: MultipleFieldErrors; | ||
} | ||
| { | ||
message?: Message; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curious tho why is it message is not required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just like register({ required: true })
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh make sense. 😆
src/useForm.ts
Outdated
| { | ||
message?: Message; | ||
type: string; | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we create type ErrorOption or Error to reduce redundancy in type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good to me 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do that after work :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could do it for you. 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commit please! 💋
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry for the delay in my review🙏
src/useForm.ts
Outdated
shouldRender: true, | ||
}); | ||
} | ||
setInternalError({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setInternalError
method is used inside only setError
method. I think you can expand setInternalError
method to setError
method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh man! totally!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Man! didn't notice it before! 😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @keiya01
we are 8 again. lol
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I miss when the lib was 2k
tho lol
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It just means it becoming useful to others because they want to stick with it and push some new features to us. 😄
@@ -28,10 +28,7 @@ export default function shouldRenderBasedOnError< | |||
const currentFieldError = get(error, name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isManual
is used inside unit test. I think you had better remove this variables from unit test.
Haha you got me first @bluebill1049 |
Thanks for your help @JeromeDeLeon 🙏 |
Nah. It was nothing compared to you. My laptop stopped responding when I was about to test locally 🤯🤯 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's nice to have less code :)
} | ||
} | ||
}; | ||
|
||
function setError(name: FieldName<TFieldValues>, error: ErrorOption): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very nice!
@keiya01 @JeromeDeLeon happy to approve? |
Thanks guys for the review. |
I think that would make things clearer, thanks @bluebill1049 |
errorsRef.current = {}; | ||
reRender(); | ||
await callback(transformToNestObject(fieldValues), e); | ||
} else { | ||
errorsRef.current = fieldErrors; | ||
errorsRef.current = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why need to merge the old error state?
setError
setError
will focus one error at a time and remove confusing set multiple errors, behavior change.setError
will persis an error if it's not part of the form, which requires manual remove withclearError
setError
error will be removed by validation rules, rules always take over errorsReason
should focus an error at a time just like the name suggested, refine the API and remove multiple errors set.
clearError
Rename to
clearErrors
Reason
This function allow remove multiple errors, so make sense to rename it to clearErrors
fix #1908