-
-
Notifications
You must be signed in to change notification settings - Fork 129
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
Handling side effects depending on "isValid" field state #344
Comments
I created a codesandbox with your code but I don't know how to replicate your issue. mobx The packages has also built-in observe/intercept methods that which might be helpful |
Oh wow, thanks for reply. I will try to prepare a sandbox (my bad, i should do it before creating an issue). I checked your codesandbox example and noticed something strange - submit doesn't trigger reaction at all, whereas in my case it does. Probably i'm doing something wrong. |
I changed the field to Previously was needed mutate the state of both |
@foxhound87 i slightly modified your example and i think i've been able to reproduce my issue: |
@foxhound87 Me, again. Obviously my issue was caused by Note that, in my sandbox example I use async function I spent few hours on debugging and still get confused by this behavior. |
why are you using async/await on |
@foxhound87 You can remove async/await and just wrap the result in a Promise - you've got the same result. Not using asynchronous validators at all won't work for me because I need to use them (e.g., emails, phone numbers, VATs etc are checked on a server side). And as I understand, |
@ekozhura |
@foxhound87 it should and it does run, but the value of |
@ekozhura |
@foxhound87 I'm not sure if I get it right, but I think this is somehow related to mobx optimization. Take a look at doc:
In case of sync validation, we have a serie of actions, which mutate the same observable. Maybe that's our case. I tried to recreate a validation flow in a sandbox without As you can see, if sync validator returns What do you think? |
@ekozhura can you make your sandbox working? |
@foxhound87 now it works, check please |
Hey, I'm trying to run some side effects like logging when field state is changing after validation. I use
mobx
reactions (maybe there are better options) to observeisValid
property and react on it:Works perfectly fine but on form submit some kind of validation reset is happening:
Whereas I prefer to get actual field state on submit:
I suspect I'm doing something wrong, maybe you can suggest a better solution?
Thanks!
The text was updated successfully, but these errors were encountered: