-
Notifications
You must be signed in to change notification settings - Fork 99
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
feat: new hook useValidator
#101
Conversation
Previous version returned wrapped function that has no name and 0 length, meaning that they do not expect arguments. Current version sets length to same value as original function.
Performs validation when any of provided dependencies has changed.
Codecov Report
@@ Coverage Diff @@
## master #101 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 27 28 +1
Lines 372 395 +23
Branches 73 77 +4
=========================================
+ Hits 372 395 +23
Continue to review full report at Codecov.
|
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.
Seems to work fine, but I'm not sold on this implementation.
); | ||
|
||
// validity state type if inferred from validator | ||
const [validity] = useValidator(validator, [validator]); |
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 don't know how I feel about this one. It almost feels like the better UX here would to be to either make this into useValidatorState, or to at least pass the value you are validating to useValidator.
Also, how it's set up here makes it so useValidator seems to be be pretty useless if you weren't using useDebounceCallback
. You could otherwise just validate on input or on render, which both seem like better practices. Maybe I'm missing something though.
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.
to either make this into useValidatorState
It will be implemented as a separate hook later.
at least pass the value you are validating to useValidator
This will strict you to use validated value only, but what if you want to validate multiple values simultaneously? How to pass them to the validator? Dependencies list is an array, attempt to determine values depending on positions can cause inambiguos bugs.
seems to be be pretty useless if you weren't using useDebounceCallback.
Althoug it supports synchronous validation - it was designed mostly for async\deferred validation.
You could otherwise just validate on input or on render, which both seem like better practices.
On-input validation makes multivalue validation very complicated complicated.
On-render validation forces you to create validity storage by hand and does validation on ach render instead of on-change.
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 was designed mostly for async\deferred validation.
How about we rename this hook to useAsyncValidator
then? Or useValidatorEffect
? I think that'd convey the intended use case better.
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 is state, not the effect, also it is not the async - only, as for my code I have several synchronous validators.
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.
Gotcha. I'm okay rolling with this for now, but I'm still not sold on it.
# [1.25.0](v1.24.1...v1.25.0) (2021-06-02) ### Features * new hook `useValidator` ([#101](#101)) ([8c517e0](8c517e0))
🎉 This PR is included in version 1.25.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
What new hook does?
Performs validation when any of provided dependencies has changed.
Checklist
react-use
#33