mstResolver: react-hook-form resolver for mobx-state-tree #2265
Unanswered
OnkelTem
asked this question in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi there!
I'm building an app with mobx-state-tree models. When it comes to forms validation, a usual solution would be to pick one of validation libs like Yup, Zod, Arktype etc. Especially if they are already integrated in the form lib of your preference.
My favorite form library is react-hook-form. Through its @hookform/resolvers package it provides integrations for around 20 different validation libraries, but not MST.
Today I added a basic support for MST to react-hook-form, but I haven't committed it anywhere, so here it is, as a snippet:
You can play with it in this sandbox.
I haven't yet tested it thoroughly. So if you find any problems - please report/fix :)
Implementation details
options.shouldUseNativeValidation && options.criteriaMode === "all"
isn't used inparseErrorSchema()
. Honestly I didn't get the idea behind what they do with it in the yupResolver that I was using as an example.Resolver
supports fields modifications during validation. I'm not sure if MST modifies anything during its validation. So I don't use this feature of theResolver
.Beta Was this translation helpful? Give feedback.
All reactions