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
cje
cje•3y ago
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 🙂
hakkub
hakkubOP•3y ago
Ahh okay. Tysm! Ahhh I would just create 1 schema object and use for both client side and trpc call.
isaac_way
isaac_way•3y ago
def use the zodResolver from @hookform/resolvers package 😄 really simplifies form creation
Want results from more Discord servers?
Add your server