Does tRPC replace client-side form validation i.e react-hook-form?
As you know tRPC has input validation in the router, but if you wanted to still have client side validation in your actual form, should you still use something like react-hook-form? I looked at the docs, and it only shows a general error i.e <pre>Error: {JSON.stringify(mutation.error.data.zodError, null, 2)}</pre>
Is there a way to display particular field errors from the mutation? Something like mutation.error.data.zodError.title for example.
Thank you for your time.
3 Replies
It doesn't replace a library like react-hook-form, but you can use the same validator for both your FE form library and your backend tRPC endpoint 🙂
Ahh okay. Tysm!
Ahhh I would just create 1 schema object and use for both client side and trpc call.
def use the zodResolver from @hookform/resolvers package 😄 really simplifies form creation