React-hook-form next-I18next ZodResolver Typescript #9452
Unanswered
tonyjara
asked this question in
Show and tell
Replies: 2 comments
-
Love it, thanks very much for sharing! we need more of those. |
Beta Was this translation helpful? Give feedback.
0 replies
-
thanks a lot |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, so I've been struggling with validation and i18next . I like having my form validations on a separate file, and for some reason the 't' from the useTranslation hook does not expose a generic type that I can easily pass down on a validation function. So anyways, this is how I solved that problem.
When using I18next with typescript we have to create a file with our imported namespaces.
Since we know that 't' takes strings concatenated strings with a semicolon, we can create a type with generics that takes the I18nNamespaces.
Now we can pass the 't' to our resolver function:
And now our validation file can has support for the 't' strings:
That's it, you can also use this new type to use 't' as a parameter anywhere else you like. Leaving this here in hopes it helps someone.
Beta Was this translation helpful? Give feedback.
All reactions